带托盘图标的WinForms应用程序

时间:2014-07-30 14:16:02

标签: vb.net winforms trayicon

我意识到一个应用程序可以在托盘图标中最小化它自己,您也可以从中显示上下文菜单。

我遇到了一些问题:

  1. 当我点击其他地方时,我无法取消上下文菜单

  2. 上下文菜单不会出现在托盘图标附近(它是黑色扳手)

    enter image description here

  3. 当我打开上下文菜单时,通常会出现一个空白任务栏项目:

    enter image description here

  4. 这是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
    

0 个答案:

没有答案