PopupMenuItem Click和MouseOver之间的区别 [英] The difference between PopupMenuItem Click and MouseOver
问题描述
当菜单项具有子菜单时,鼠标悬停以展开子菜单,它将触发单击事件。
When a Menu Item has a sub Menu hovering the mouse expands the sub-menu it fires a click event.
此单击事件与是否在点击事件之间有什么区别?用户实际点击了吗?
Is there any difference between this click event and if the user actually clicks?
我正在使用TPopupMenu作为cxButton的下拉属性。
I'm using a TPopupMenu as dropdown property of a cxButton.
EDIT
Delphi 2007
EDIT Delphi 2007
推荐答案
不确定该方法是否适用于D2007;在D7中您可以尝试以下操作吗?
Not sure this will work with D2007; it does in D7. Can you try the following?
type
THackPopupList = class(TPopupList)
private
FActuallyClicked: Boolean;
protected
procedure WndProc(var Message: TMessage); override;
public
property ActuallyClicked: Boolean read FActuallyClicked;
end;
{ THackPopupList }
procedure THackPopupList.WndProc(var Message: TMessage);
begin
FActuallyClicked := Message.Msg = WM_COMMAND;
inherited WndProc(Message);
end;
{ TForm1 }
procedure TForm1.MenuFileOpenClick(Sender: TObject);
var
ActuallyClicked: Boolean;
begin
ActuallyClicked := THackPopupList(PopupList).ActuallyClicked;
...
end;
initialization
PopupList.Free;
PopupList := THackPopupList.Create;
end.
说明:由悬停触发的OnClick由WM_INITMENUPOPUP启动,但由通过鼠标单击触发的触发由此WM_COMMAND启动。
Explanation: The OnClick which is triggered by a hover is initiated by a WM_INITMENUPOPUP, but the OnClick which is triggered by a mouse click is initiated by this WM_COMMAND.
这取决于已经初始化的Menus.pas。但是据 Delphi单元初始化顺序所了解,即使您将此代码放在辅助单元中。
This depends on Menus.pas already having been initialized. But as I understand from Delphi unit initialization order, that is guaranteed even if you put this code in an auxiliary unit.
这篇关于PopupMenuItem Click和MouseOver之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!