实现Button双击事件。procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if ssDouble in Shift then showmessage('你点了双击'); end;
哈哈,樓主,試試我的辦法不是的,双击的时候首先触发单击事件,完了又触发单击事件,所以主窗体form1没有获得焦点 -------> 雙擊完是不會再觸發單擊事件的,但會觸發mousedown事件 所以解決的方法是: 把這部分代碼 case button of mbleft: begin releasecapture; perform(WM_SYSCOMMAND,$F012,0); // if form1.showing then // form1.SetFocus; end; 放到onclick事件去寫; onmousedown 只留下控制右鍵的部分.應該可以解決的:)
jackie168(花好月圓) ( ) 信誉:131 這個辦法應該可以了吧,呵呵
给 wangbohziee() : 其实单击(click)和按下鼠标(mousedown)是有区别的,click先触发mousedown,再是mouseup再click的,双几也是这样的,先mousedoun,在mouseup,在dbclick,再mousedown,再mouseup,我们可以做个这样的测试: procedure TForm1.mousedown(Sender: TObject); begin if button=mbleft then Edit1.Text := Edit1.Text + '#'; end;procedure TForm1.FormDblClick(Sender: TObject); begin Edit2.Text := Edit2.Text + '1'; end; procedure TForm1.FormClick(Sender: TObject); begin Edit1.Text := Edit1.Text + '2'; end; 你运行一个就知道了
用jackie168(花好月圓)的辦法 -> procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var cursorpos:tpoint;begin case button of mbleft: begin releasecapture; perform(WM_SYSCOMMAND,$F012,0); if form1.showing then form1.SetFocus; end; mbright: begin GetCursorPos(cursorpos); form1.PopupMenu1.Popup(cursorpos.X,cursorpos.y); end; end;
//雙擊事件寫在這裡 if ssdouble in shift then begin setwindowlong(application.Handle,GWL_EXSTYLE,WS_EX_APPWINDOW); showwindow(form1.Handle,sw_show); showwindow(application.Handle,sw_show); setforegroundwindow(application.Handle); end;end; 你試試看看
上楼的,你说的真好啊,问题已经解决啊,呵呵, 但是要把在button=mbleft里面的if form1.showing then form1.setfocus 行去掉就ok 谢谢,已给分
bein
双击代码
end;
procedur TForm1.FormClick
begin
单击代码
end;
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ExtCtrls;type
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormDblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure createparams(var params:TCreateparams);override;
//重载form2的createparams方法,把窗体样式改写。
end;var
Form2: TForm2;implementation
uses unit1;
{$R *.dfm}procedure TForm2.createparams(var params: TCreateparams);
begin
inherited;
with params do
begin
Style := Params.Style xor WS_DLGFRAME;
wndparent:=GetDesktopWindow; //让form2的父窗口为桌面。
end;
end;procedure TForm2.FormCreate(Sender: TObject);
begin
setwindowlong(handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
height:=50;
width:=50;
end;
procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var cursorpos:tpoint;begin
case button of
mbleft:
begin
releasecapture;
perform(WM_SYSCOMMAND,$F012,0);
// if form1.showing then
// form1.SetFocus; end;
mbright:
begin
GetCursorPos(cursorpos);
form1.PopupMenu1.Popup(cursorpos.X,cursorpos.y);
end;
end;end;
procedure TForm2.FormDblClick(Sender: TObject);
begin
setwindowlong(application.Handle,GWL_EXSTYLE,WS_EX_APPWINDOW);
showwindow(form1.Handle,sw_show);
showwindow(application.Handle,sw_show);
setforegroundwindow(application.Handle);
end;end.
如果在单击里写上if form1.showing then form1.setfocus;
则单击鼠标也同样的能够让主窗体显示出来啊,就是想让他只有双击的时候才显示啊
或者还有其他的好办法吗?
两次激发的都是鼠标单击事件。建议楼主模拟单击选中窗口,双击放大窗口的方法,因为那样必须先进行判断。
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ExtCtrls;type
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormDblClick(Sender: TObject);
procedure FormClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure createparams(var params:TCreateparams);override;
//重载form2的createparams方法,把窗体样式改写。
end;var
Form2: TForm2;implementation
uses unit1;
{$R *.dfm}procedure TForm2.createparams(var params: TCreateparams);
begin
inherited;
with params do
begin
Style := Params.Style xor WS_DLGFRAME;
wndparent:=GetDesktopWindow; //让form2的父窗口为桌面。
end;
end;procedure TForm2.FormCreate(Sender: TObject);
begin
setwindowlong(handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
height:=50;
width:=50;
end;
procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var cursorpos:tpoint;begin
case button of
{ mbleft:
begin
releasecapture;
perform(WM_SYSCOMMAND,$F012,0);
if form1.showing then
form1.SetFocus; end;}
mbright:
begin
GetCursorPos(cursorpos);
form1.PopupMenu1.Popup(cursorpos.X,cursorpos.y);
end;
end;end;
procedure TForm2.FormDblClick(Sender: TObject);
begin
setwindowlong(application.Handle,GWL_EXSTYLE,WS_EX_APPWINDOW);
showwindow(form1.Handle,sw_show);
showwindow(application.Handle,sw_show);
setforegroundwindow(application.Handle);
end;procedure TForm2.FormClick(Sender: TObject);
begin
releasecapture;
perform(WM_SYSCOMMAND,$F012,0);
// if form1.showing then
// form1.SetFocus;
end;
end.
我写了这样的简单事件:
procedure TForm1.FormClick(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '*';
end;procedure TForm1.FormDblClick(Sender: TObject);
begin
Edit2.Text := Edit2.Text + '#';
end;
然后双击窗体,但Edit1的text只有一个‘*’
如果双击会连续触发两次单击事件,那应该是两个‘*’,我的理解错了吗?谢谢!
Shift: TShiftState; X, Y: Integer);
begin
if ssDouble in Shift then
showmessage('你点了双击');
end;
------->
雙擊完是不會再觸發單擊事件的,但會觸發mousedown事件
所以解決的方法是:
把這部分代碼
case button of
mbleft:
begin
releasecapture;
perform(WM_SYSCOMMAND,$F012,0);
// if form1.showing then
// form1.SetFocus; end;
放到onclick事件去寫;
onmousedown 只留下控制右鍵的部分.應該可以解決的:)
這個辦法應該可以了吧,呵呵
其实单击(click)和按下鼠标(mousedown)是有区别的,click先触发mousedown,再是mouseup再click的,双几也是这样的,先mousedoun,在mouseup,在dbclick,再mousedown,再mouseup,我们可以做个这样的测试:
procedure TForm1.mousedown(Sender: TObject);
begin
if button=mbleft then
Edit1.Text := Edit1.Text + '#';
end;procedure TForm1.FormDblClick(Sender: TObject);
begin
Edit2.Text := Edit2.Text + '1';
end;
procedure TForm1.FormClick(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '2';
end;
你运行一个就知道了
你的办法我也用了啊,是可以,但是这样的话就不能够拖动悬浮窗,也就是form2,因为拖动只能够在mousedown或者mouseover事件里面
->
procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var cursorpos:tpoint;begin
case button of
mbleft:
begin
releasecapture;
perform(WM_SYSCOMMAND,$F012,0);
if form1.showing then
form1.SetFocus; end;
mbright:
begin
GetCursorPos(cursorpos);
form1.PopupMenu1.Popup(cursorpos.X,cursorpos.y);
end;
end;
//雙擊事件寫在這裡
if ssdouble in shift then
begin
setwindowlong(application.Handle,GWL_EXSTYLE,WS_EX_APPWINDOW);
showwindow(form1.Handle,sw_show);
showwindow(application.Handle,sw_show);
setforegroundwindow(application.Handle);
end;end;
你試試看看
但是要把在button=mbleft里面的if form1.showing then form1.setfocus 行去掉就ok
谢谢,已给分