Minimize to System Tray

Add the NotifyIcon component to a the main form in the application. Add a context menu strip to right click in the tray and have commands available.
 
Add a Notify Icon control to your form (Under Common Controls) then do something like this
VB.NET:
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            Me.Hide()
        End If
End Sub
 
Anyone knows why sometimes my system tray icon keeps sitting in the tray
even when I closed my program. I have to hang over it to make it dissapear... I've tried dispose, visible=false,... when form is closing.....

Thought it would be nice to mention this here aswell. :)
 
There's not much code to it.
Like your example, I hide the form but the system tray icon only shows
when the user minimizes the form.(on purpose) Now whenever I close the form from my context menu or stop from designer the icon keeps hanging there until
I hover my mouse over it...
 
Back
Top