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:
I can't get the Context menu to disappear when I click somewhere else
The Context menu doesn't appear exacly near the tray icon (it's the black wrench)
When I open the Context menu, often a blank taskbar item appears:
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