0

I realized an application that minimize it self in a tray icon, from which you can also show a context menu.

I'm facing some problems:

  1. I can't get the Context menu to disappear when I click somewhere else

  2. The Context menu doesn't appear exacly near the tray icon (it's the black wrench)

    enter image description here

  3. When I open the Context menu, often a blank taskbar item appears:

    enter image description here

This is the code of the Form Resize handler and the TrayIcon Click handler:

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
Community
  • 1
  • 1
Teejay
  • 7,210
  • 10
  • 45
  • 76
  • Otherwise the reason that tray icons display a menu only on a right-click. As context menus should work. The underlying problem is a Windows bug, the dup shows a solution that takes advantage of a bug workaround built into the .NET NotifyIcon class. – Hans Passant Jul 30 '14 at 14:37
  • @HansPassant Thank you for the redirection to the correct answer. – Teejay Jul 30 '14 at 14:45

0 Answers0