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