我有一个带有 CoolTrayIcon
和 PopupMenu
的项目,并且禁用了 AutoPopup
属性。
我想定位 PopupMenu 并向用户显示它。
该位置正常,但如果用户单击或按 ESC 按钮,菜单不会关闭。
我还没有找到任何像 Active
这样的属性,如果菜单使用或不使用,它可以提供帮助。
这里我放置菜单:
procedure TForm1.CoolTrayIcon1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
pnt: TPoint; yy:integer;
begin
GetCursorPos(pnt);
yy:=pnt.y; yy:=yy-500;
if (Button=mbRight) then begin
PopupMenu1.Popup(pnt.X, yy);
end;
end;
如果需要,我怎样才能关闭菜单?
最佳答案
这是一个已知问题,在此讨论:
PRB: Menus for Notification Icons Do Not Work Correctly
您需要按如下方式包装对 Popup()
的调用:
SetForegroundWindow(Handle);
PopupMenu1.Popup(pnt.X, yy);
PostMessage(Handle, WM_NULL, 0, 0);
在此代码中,Handle
是与通知图标关联的表单的窗口句柄。
关于delphi - 如何在delphi中关闭自定义定位的PopupMenu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37789882/