[VB.NET] Minimize To System Tray

Discussion in 'Code Snippets and Tutorials' started by Lightning, Jun 30, 2010.

  1. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    I thought this simplez little code would maybe be useful because I couldn't find anything with 'minimize to tray'.

    Code (Text):
    1. #Region "Minimize To Tray"
    2.  
    3.     Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    4.  
    5.         If chkminimize.Checked Then
    6.             If Me.WindowState = FormWindowState.Minimized Then
    7.                 Me.Hide()
    8.                 'Optional: only if your icon doesn't already run in the tray
    9.                 NotifyIcon1.Visible = True
    10.             End If
    11.         End If
    12.     End Sub
    13.     Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
    14.  
    15.         If Me.WindowState = FormWindowState.Minimized Then
    16.             Me.Show()
    17.             'Optional: only if you don't want an icon to run while your program is not minimized to tray
    18.             'NotifyIcon1.Visible = False
    19.         End If
    20.     End Sub
    21. #End Region