Click here to Skip to main content
15,896,557 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
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class MainForm
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.MenuStrip1 = New System.Windows.Forms.MenuStrip
        Me.mnuForm = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuFormMinimize = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuFormClose = New System.Windows.Forms.ToolStripMenuItem
        Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripSeparator
        Me.mnuFormExit = New System.Windows.Forms.ToolStripMenuItem
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TimeLabel = New System.Windows.Forms.Label
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.MenuStrip1.SuspendLayout()
        Me.SuspendLayout()
        '
        'MenuStrip1
        '
        Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuForm})
        Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
        Me.MenuStrip1.Name = "MenuStrip1"
        Me.MenuStrip1.Size = New System.Drawing.Size(299, 24)
        Me.MenuStrip1.TabIndex = 0
        Me.MenuStrip1.Text = "MenuStrip1"
        '
        'mnuForm
        '
        Me.mnuForm.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuFormMinimize, Me.mnuFormClose, Me.ToolStripMenuItem1, Me.mnuFormExit})
        Me.mnuForm.Name = "mnuForm"
        Me.mnuForm.Size = New System.Drawing.Size(47, 20)
        Me.mnuForm.Text = "&Form"
        '
        'mnuFormMinimize
        '
        Me.mnuFormMinimize.Name = "mnuFormMinimize"
        Me.mnuFormMinimize.Size = New System.Drawing.Size(152, 22)
        Me.mnuFormMinimize.Text = "&Minimize"
        '
        'mnuFormClose
        '
        Me.mnuFormClose.Name = "mnuFormClose"
        Me.mnuFormClose.Size = New System.Drawing.Size(152, 22)
        Me.mnuFormClose.Text = "&Close"
        '
        'ToolStripMenuItem1
        '
        Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1"
        Me.ToolStripMenuItem1.Size = New System.Drawing.Size(149, 6)
        '
        'mnuFormExit
        '
        Me.mnuFormExit.Name = "mnuFormExit"
        Me.mnuFormExit.Size = New System.Drawing.Size(152, 22)
        Me.mnuFormExit.Text = "E&xit"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(4, 32)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(100, 20)
        Me.TextBox1.TabIndex = 1
        '
        'TimeLabel
        '
        Me.TimeLabel.AutoSize = True
        Me.TimeLabel.Location = New System.Drawing.Point(120, 36)
        Me.TimeLabel.Name = "TimeLabel"
        Me.TimeLabel.Size = New System.Drawing.Size(39, 13)
        Me.TimeLabel.TabIndex = 2
        Me.TimeLabel.Text = "Label1"
        '
        'Timer1
        '
        '
        'MainForm
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(299, 57)
        Me.Controls.Add(Me.TimeLabel)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.MenuStrip1)
        Me.MainMenuStrip = Me.MenuStrip1
        Me.MaximizeBox = False
        Me.Name = "MainForm"
        Me.Text = "Close to Notification Area Demo"
        Me.MenuStrip1.ResumeLayout(False)
        Me.MenuStrip1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
    Friend WithEvents mnuForm As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuFormMinimize As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuFormClose As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripSeparator
    Friend WithEvents mnuFormExit As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TimeLabel As System.Windows.Forms.Label
    Friend WithEvents Timer1 As System.Windows.Forms.Timer

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