怎样使单击事件变为双击事件(50分)

即单击时并不产生单击事件,而双击时产生单击事件,这样不能在
双击事件里调用单击事件,因单击事件优先于双击事件。


拦截单击的消息,改发双击的消息


能否举个例子!以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,。。。

posted on 2019-01-06 00:24  癫狂编程  阅读(617)  评论(0编辑  收藏  举报

导航

好的代码像粥一样,都是用时间熬出来的