Task Tray

This will show you how to put an Icon in the Task Tray and make a Menu appear when you right click on the Icon in the Task Tray.


Step 1

Start Microsoft Visual Basic 2005 Express Edition, then select File then New Project... Choose Windows Application from the New Project Window, enter a name for the Project and then click OK, see below:

New Project

Step 2

A Blank Form named Form1 should then appear, see below:


Step 3

Scroll down the Windows Forms Components tab and select the NotifyIcon control:

NotifyIcon Control

Step 4

Draw the NotifyIcon control on Form1 and it will appear in the pane, beneath the form, see below:

NotifyIcon Control in Pane

Step 5

Scroll down the Windows Forms Components tab and select the ContextMenuStrip control:

ContextMenuStrip Control

Step 6

Draw the ContextMenuStrip control on the form, see below:

Form with ContextMenu

Step 7

Make sure the ContextMenuStrip1 control is selected in the Pane beneath the form then Click on the ContextMenuStrip at the top of Form1 and change Type Here to Exit by clicking on the text and typing in the new value, see below:

Form with ContextMenu with Exit

Step 8

Double click where you typed Exit on the ContextMenuStrip and enter the following in the ExitToolStripMenuItem_Click sub:


See Below:

ContextMenu MenuItem Click Event

Step 9

Click on the NotifyIcon1 control in the Pane beneath Form1, then go to the Properties box and set the ContextMenu property to ContextMenu1, see below:

NotifyIcon Properties

Step 10

Double Click on Form1 and type in the Form1_Load Sub:

NotifyIcon1.Icon = Me.Icon
NotifyIcon1.Visible = True
NotifyIcon1.Text = "Task Tray"

See Below:

Form1 Load Event

Step 11

Save the Project as you have now finished the application, then click on Start:


When you do the following will appear in the Task Tray:

Application Running

Step 12

Now right click on the icon shown in the Task Tray and a menu should appear, see below:

Task Tray Menu

Step 13

Click on Exit on the menu to end the application. Try Changing the Form Icon or add other Sub Menus to the ContextMenuPanel and see what happens!