我正在尝试使一个NotifyIcon
显示一个上下文菜单,即使它是通过左键点击的。 我可以在图标的MouseDown
事件中使用以下代码将其显示在正确的位置:
sysTrayIcon.ContextMenuStrip = TrayContextMenu
If e.Button = MouseButtons.Left Then TrayContextMenu.Show()
但是因为当我左键点击时不会将sysTrayIcon
指定为控件,所以如果我在菜单外面点击或按下esc键,它就不会从屏幕上清除。
我知道通常的方法是使用菜单重载的Show(control, location)
方法,但这会引发错误:
Value of type 'System.Windows.Forms.NotifyIcon' cannot be converted to 'System.Windows.Forms.Control'.
那么,我该如何将菜单附加到通知图标呢?