Click here to Skip to main content
15,896,296 members
Articles / Desktop Programming / Windows Forms

Close Your Application to the Notification Area

Rate me:
Please Sign up or sign in to vote.
4.61/5 (12 votes)
25 Aug 2010CPOL5 min read 48.4K   1.8K   38  
How to write an app that will go to the system tray when the user closes it
Public Class MainForm

#Region " Constructors "

    Public Sub New()
        InitializeComponent()

        TimeLabel.Text = DateTime.Now.ToString
        TimerMenu.Text = TimeLabel.Text

        Timer1.Interval = 1000
        Timer1.Start()
    End Sub

#End Region

#Region " Event handlers "

    Private Sub MainForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) _
    Handles Me.FormClosing
        If e.CloseReason = CloseReason.UserClosing Then
            e.Cancel = True
            CloseApp()
        End If
    End Sub

    Private Sub mnuFormClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles mnuFormClose.Click
        CloseApp()
    End Sub

    Private Sub mnuFormExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles mnuFormExit.Click
        ExitApp()
    End Sub

    Private Sub mnuFormMinimize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles mnuFormMinimize.Click
        MinimizeApp()
    End Sub

#End Region

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        TimeLabel.Text = DateTime.Now.ToString
        TimerMenu.Text = TimeLabel.Text
    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
United States United States
Gregory Gadow recently graduated from Central Washington University with a B.S. that combined economics and statistical analysis, and currently works for the Washington Department of Fish & Wildlife as an IT developer. He has been writing code for 30 years in more than a dozen programming languages, including Visual Basic, VB.Net, C++, C#, ASP, HTML, XML, SQL, and R.

Comments and Discussions