Click here to Skip to main content
15,884,083 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Minimize Form in System Tray

Rate me:
Please Sign up or sign in to vote.
3.00/5 (4 votes)
12 Feb 2010CPOL 33.3K   8   4
Note that you must select NotifyIcon1 from the ToolBox and set any icon to its icon property plus make 3 buttons or you can write minimize to tray code in the form closing event.Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As...
Note that you must select NotifyIcon1 from the ToolBox and set any icon to its icon property plus make 3 buttons or you can write minimize to tray code in the form closing event.

VB.NET
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button2.Click
        Application.Exit()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button3.Click
        Me.WindowState = FormWindowState.Minimized
        Me.Visible = False
        NotifyIcon1.Visible = True
    End Sub

    Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, _
        ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
        Me.Visible = True
        Me.WindowState = FormWindowState.Normal
        NotifyIcon1.Visible = False
    End Sub
End Class

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
alex.barylski20-Feb-13 6:23
alex.barylski20-Feb-13 6:23 
QuestionAlternate Pin
AspDotNetDev12-Feb-10 19:59
protectorAspDotNetDev12-Feb-10 19:59 
What does your alternate have to do with your tip/trick? Typically, alternates would be used to list alternate ways of accomplishing the same thing that is done in the tip/trick. I'm not sure what your alternate does, but it seems to be unrelated to your tip/trick.

Also, just an FYI, I formatted your code for you trip trick. I didn't format your code for your alternate because I'm thinking of deleting it for you (unless you have a good reason for keeping it there).
AnswerRe: Alternate Pin
Luc Pattyn23-Jul-10 3:55
sitebuilderLuc Pattyn23-Jul-10 3:55 
GeneralRe: Alternate Pin
AspDotNetDev23-Jul-10 5:08
protectorAspDotNetDev23-Jul-10 5:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.