在其他地方单击时,VB.NET隐藏NotifiyIcon ContextMenuStrip

时间:2019-04-04 09:14:18

标签: vb.net

我的表单包括带有ContexMenu的Notify图标。单击任何项​​目时(AutoClose = True),ContextMenu将自动关闭。但是,如果我单击其他任何地方(远离上下文菜单),则ContextMenu仍然可见。在这种情况下如何隐藏它?

找到一个答案,即单击其他位置时隐藏上下文菜单是上下文菜单的标准行为。就我而言,它不起作用:)。

我试图使用ContextMenuStrip离开或LostFocus事件来隐藏,但这没有用。

显示上下文菜单:

Private Sub NotifyIcon1_DoubleClick(sender As Object, e As EventArgs) 
                        Handles NotifyIcon1.DoubleClick
    NotifyIcon1.ContextMenuStrip.Show(MousePosition)
End Sub

我试图隐藏上下文菜单:

Private Sub ContextMenuStrip_Leave(sender As Object, e As EventArgs) 
                        Handles ContextMenuStrip.Leave
    NotifyIcon1.ContextMenuStrip.Hide()
End Sub

Private Sub ContextMenuStrip_LostFocus(sender As Object, e As EventArgs) 
                        Handles ContextMenuStrip.LostFocus
    NotifyIcon1.ContextMenuStrip.Hide()
End Sub

更新:这有效:

Private Sub ContextMenuStrip_MouseLeave(sender As Object, e As EventArgs) 
                         Handles ContextMenuStrip.MouseLeave
    NotifyIcon1.ContextMenuStrip.Hide()
End Sub

可以用作临时解决方案,但原始问题仍未解决。

0 个答案:

没有答案