全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1296
推到 Plurk!
推到 Facebook!

請教 popmune 左鍵(左鍵喔不是右鍵喔)喚起功能

答題得分者是:jazz
smartboss
初階會員


發表:19
回覆:93
積分:42
註冊:2004-12-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-21 12:55:31 IP:218.170.xxx.xxx 未訂閱
請問站上大大:   小弟做了一個 popmune ,但我要使它按左鍵(是左鍵喔不是右鍵喔)時mune 出現,我的做法是如下:
void __fastcall TAskBox::StringGrid1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
           StringGrid1->PopupMenu->Popup(X,Y);
}
假設 x,y 分別為 10,10 而以上的秀法 mune 將出現在 form 的 X,Y = 10,10 的地方,而不會出現在 stringgrid1 的 moousedown 位置,如何能讓它的功能像按右鍵叫出mune功能 一樣,就出現在stringgrid1 的 moousedown 位置,而以下方法小弟用過,
void __fastcall TAskBox::StringGrid1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
           StringGrid1->PopupMenu->Popup(
                 StringGrid1-Left X,StringGrid1->Top Y);
}
但是我覺得這並不實用,因為小弟版面可能會改或許會在 stringgrid 之前又加個 pagecontorl 或是 groupbox 等....之類的,這樣以上那個寫法就要重新 計算考慮,因此小弟想得知,是否有func 不管我們的 mouse 在哪個物件上 mousedown 它都能算出它在 form 上的x,y,或者能像按右鍵叫出mune功能 一樣,就在mouse 的位置,謝謝,以下是我查的資料,要求很類似,但小弟 還是不董,請站上大大指教??? http://delphi.ktop.com.tw/topic.php?topic_id=26112 蝦程速,有了 K.TOP 尊好。
limeca
中階會員


發表:2
回覆:74
積分:60
註冊:2005-05-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-21 13:44:46 IP:202.145.xxx.xxx 未訂閱
你好~~ 不知下面是不是你要的結果~~ 可以參考一下 先定義一個全域變數 POINT MousePos; 再來在MouseDown orUp加入下面兩行
void __fastcall TFormMain::FormMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
   MousePos.x=X;
   MousePos.y=Y;
   if(Button==mbLeft){
      MousePos=ClientToScreen(MousePos);
      PopupMenu1->Popup(MousePos.x, MousePos.y);
   }     
}
把PopupMenu1的AutoPopup設定為false; 這樣才不會按滑鼠右鍵又自動出現 發表人 - limeca 於 2005/07/21 14:26:45
smartboss
初階會員


發表:19
回覆:93
積分:42
註冊:2004-12-29

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-07-21 14:54:13 IP:218.170.xxx.xxx 未訂閱
引言: 先定義一個全域變數 POINT MousePos; 再來在MouseDown orUp加入下面兩行
void __fastcall TFormMain::FormMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
   MousePos.x=X;
   MousePos.y=Y;
   if(Button==mbLeft){
      MousePos=ClientToScreen(MousePos);
      PopupMenu1->Popup(MousePos.x, MousePos.y);
   }     
}
把PopupMenu1的AutoPopup設定為false; 這樣才不會按滑鼠右鍵又自動出現
limeca 您好: 感謝您的回答,但您的方法與小弟所提的
           StringGrid1->PopupMenu->Popup(
                 StringGrid1-Left+X,StringGrid1->Top+Y);
是一樣的,如下圖: 而如果只是直接在 mousedown 中使用 popup(x,y) 則如下圖: 而小弟想要的是像按右鍵一樣,按下左鍵後 menu 會出現在 mouse 的地方, 如下圖: 雖然答案並非小弟所要,但還是很感謝您的答覆,謝謝您。 蝦程速,有了 K.TOP 尊好。 發表人 - smartboss 於 2005/07/21 15:03:34
jazz
初階會員


發表:10
回覆:43
積分:35
註冊:2002-06-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-07-21 23:11:04 IP:61.62.xxx.xxx 未訂閱
不知道這樣有沒有解決你的問題  
void __fastcall TForm1::StringGrid1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
    if (Button == mbLeft){
        LPPOINT p;
        GetCursorPos(p);
        PopupMenu1->Popup(p->x, p->y);
    }
}
 
請注意 StringGrid1的PopupMenu屬性不需要去設定
smartboss
初階會員


發表:19
回覆:93
積分:42
註冊:2004-12-29

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-07-21 23:50:49 IP:218.170.xxx.xxx 未訂閱
引言:
void __fastcall TForm1::StringGrid1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
    if (Button == mbLeft){
        LPPOINT p;
        GetCursorPos(p);
        PopupMenu1->Popup(p->x, p->y);
    }
}
 
JAZZ 您好,謝謝您回覆的答案小弟己經知道意思了,只是有一點小小的問題, LPPOINT p;好像是指標所以跑到 PopupMenu1->Popup(p->x, p->y);時就掛了, 因此小弟修改了您的程式如下:
        TPoint   pt;
        if (Button == mbLeft){
           pt.x = X;
           pt.y = Y;
           GetCursorPos(&pt);
           PopupMenu->Popup(pt.x, pt.y);
        }
現在己經能跑了,感謝您的指導,謝謝您! 蝦程速,有了 K.TOP 尊好。
系統時間:2024-05-12 23:40:01
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!