views:

3161

answers:

5

What needs to be done to have your .NET application show up in Window's system tray as icon?

And how do you handle mousebutton clicks on said icon?

+6  A: 

You can add the NotifyIcon component from the toolbox onto your main form.

This has events such as MouseDoubleClick that you can use to handle various events.

Edit: You have to make sure that you set the Icon property to a valid .ico file if you want it to show up properly in the systray.

Carl
+2  A: 

Nice little tutorial on using the NotifyIcon class here: http://www.developer.com/net/csharp/article.php/3336751

Geoffrey Chetwood
A: 

Add NotifyIcon component to your form. And use it's events to handle mouse clicks.

Vivek
+4  A: 

First, add a NotifyIcon control to the form. Then wire up the Notify Icon to do what you want.

If you want it to hide to tray on minimize, try this.

Private Sub frmMain_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    If Me.WindowState = FormWindowState.Minimized Then
        Me.ShowInTaskbar = False
    Else
        Me.ShowInTaskbar = True
    End If
End Sub

Private Sub NotifyIcon1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
    Me.WindowState = FormWindowState.Normal
End Sub

I'll occasionally use the Balloon Text in order to notify a user - that is done as such

 Me.NotifyIcon1.ShowBalloonTip(3000, "This is a notification title!!", "This is notification text.", ToolTipIcon.Info)
tom.dietrich
A: 

This shows and handles all the mouse click combinations for NotifyIcon

More here: http://code.msdn.microsoft.com/TheNotifyIconExample