PopupMenuItem Click 和 MouseOver 的区别

发布于 2024-11-14 22:34:14 字数 146 浏览 4 评论 0原文

当菜单项有一个子菜单时,鼠标悬停在展开子菜单时会触发单击事件。

这个点击事件和用户实际点击有什么区别吗?

我使用 TPopupMenu 作为 cxButton 的下拉属性。

编辑 德尔福2007

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?

I'm using a TPopupMenu as dropdown property of a cxButton.

EDIT
Delphi 2007

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初心 2024-11-21 22:34:15

不确定这是否适用于 D2007;在 D7 中也是如此。你可以尝试以下方法吗?

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发起的,而鼠标点击触发的OnClick是由这个WM_COMMAND发起的。

这取决于已初始化的 Menus.pas。但据我从 Delphi 单元初始化顺序 了解到,即使您将此代码放入辅助单元中。

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.

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.

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.

长安忆 2024-11-21 22:34:15

那么,如果用户实际单击带有子菜单项的 MenuItem,则不会触发 OnClick 事件。因此,区别在于:

procedure TForm1.MenuFileOpenClick(Sender: TObject);
var
  ActuallyClicked: Boolean;
begin
  ActuallyCLicked := TMenuItem(Sender).Count = 0;
end;

如果菜单项具有链接操作:

procedure TForm1.FileOpenExecute(Sender: TObject);
var
  ActuallyClicked: Boolean;
begin
  if Sender is TBasicAction then
    Sender := TBasicAction(Sender).ActionComponent;
  ActuallyCLicked := TMenuItem(Sender).Count = 0;
end;

Well, if the user actually clicks a MenuItem with sub menu items, the OnClick event is not fired. So the distinction is made by:

procedure TForm1.MenuFileOpenClick(Sender: TObject);
var
  ActuallyClicked: Boolean;
begin
  ActuallyCLicked := TMenuItem(Sender).Count = 0;
end;

And if the menu item has a linked action:

procedure TForm1.FileOpenExecute(Sender: TObject);
var
  ActuallyClicked: Boolean;
begin
  if Sender is TBasicAction then
    Sender := TBasicAction(Sender).ActionComponent;
  ActuallyCLicked := TMenuItem(Sender).Count = 0;
end;
那请放手 2024-11-21 22:34:15

不,没有。如果用户单击该项目或将其悬停在该项目上,则会触发相同的 OnClick 事件。
我已经针对 Delphi 2009 检查了这一点。

No there isn't. If the user clicks the item or hover it, the same OnClick event is fired.
I've checked this for Delphi 2009.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文