怎樣使單擊事件變為雙擊事件(50分)
阿新 • • 發佈:2019-01-06
即單擊時並不產生單擊事件,而雙擊時產生單擊事件,這樣不能在
雙擊事件裡呼叫單擊事件,因單擊事件優先於雙擊事件。
攔截單擊的訊息,改發雙擊的訊息
能否舉個例子!以DBgridclick()為例
TForm1 = class(TForm) procedure FormClick(Sender: TObject); procedure FormDblClick(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations} Flag: Boolean; end; var Form1: TForm1; implementation {$R *.DFM} { TForm1 } procedure TForm1.FormClick(Sender: TObject); begin if Flag then begin ShowMessage ('You click me!'); Flag := False; end; end; procedure TForm1.FormDblClick(Sender: TObject); begin Flag := True; FormClick(Self);end; procedure TForm1.FormCreate(Sender: TObject); begin Flag := False; end;
攔截訊息 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,MaxDirFile; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations} protected procedure WL(var Message:TWMLBUTTONDOWN);message WM_LBUTTONDOWN; procedure WDL(var Message:TWMLBUTTONDBLCLK);message WM_LBUTTONDBLCLK; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); begin MaxDirFile.GetAppDir end; procedure TForm1.WDL(var Message: TWMLBUTTONDBLCLK); begin Showmessage('ddd'); Message.Result:=0; end; procedure TForm1.WL(var Message: TWMLBUTTONDOWN); Var Pos:Integer; Key:integer; begin Pos:=(Message.YPos shl 16)+Message.XPos; Key:=Message.Keys; SendMessage(handle,WM_LBUTTONDBLCLK,Key,Pos); Message.Result:=-1; end; end.
呵呵,還有一招……
比如按鈕的單擊事件,你可以設定一個布林量 B:=false;
每次 click 時先判斷 B=true 再執行你的事件,然後改變 B一次。
這樣一來就用兩個單擊代替了雙擊,如果效果不好就結合時間……
不如是整型,每CLICK一下加一,加到2時用DBCLICK,然後清0,。。。