Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在构建没有显示任何表单的 winform 应用程序(表单的不透明度为 0,ShowInTaskbar 属性为 false)。它只能从托盘通知图标访问。当用户用鼠标左键单击它时,将显示 contextMenustrip 菜单。因为我想检测鼠标左键单击,所以不能使用 NotifyIcon 的 ContextMenu 属性。
我想,如果用户在菜单外点击,它应该隐藏。我不知道我该怎么做...
如果我显示了表单,我可以检测到停用表单事件,然后隐藏我的菜单,但在所描述的情况下它看起来更难。
1) Instead of setting opacity to 0 better set WindowState = FormWindowState.Minimized
WindowState = FormWindowState.Minimized
2) You cant detect mouse clicks outside of your program as they are controlled by other programs or your OS, but handling Leave or MouseLeave event should help you
Leave
MouseLeave