我意识到一个应用程序可以在托盘图标中最小化它自己,您也可以从中显示上下文菜单。
我遇到了一些问题:
当我点击其他地方时,我无法取消上下文菜单
上下文菜单不会出现在托盘图标附近(它是黑色扳手)
当我打开上下文菜单时,通常会出现一个空白任务栏项目:
这是Form Resize处理程序和TrayIcon Click处理程序的代码:
Private Sub MainForm_Resize(snd As Object, e As EventArgs) Handles Me.Resize
If WindowState = FormWindowState.Minimized Then
Me.TrayIcon.Visible = True
Me.ShowInTaskbar = False
Me.Hide()
End If
End Sub
Private Sub TrayIcon_Click(snd As Object, e As EventArgs) Handles TrayIcon.Click
Dim castedEvent As MouseEventArgs = DirectCast(e, MouseEventArgs)
If (castedEvent.Button = Windows.Forms.MouseButtons.Left) Then
Me.Show()
Me.ShowInTaskbar = True
Me.TrayIcon.Visible = False
Me.WindowState = FormWindowState.Normal
Else
TrayIconContextMenu.Show(Control.MousePosition)
End If
End Sub