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?
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?
Add NotifyIcon component to your form. And use it's events to handle mouse clicks.
This shows and handles all the mouse click combinations for NotifyIcon
More here: https://archive.codeplex.com/?p=notifyicon
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.
To extend Tom's answer, I like to only make the icon visible if the application is minimized.
To do this, set
Visible = False
for NotifyIcon and use the below code.I also have code below to hide the icon during close the prevent the annoying ghost tray icons that persist after application close.
If you want to add a right click menu:
VB.NET: How to Make a Right Click Menu for a Tray Icon
Per the article (with mods for context):
Setting up the Form for hosting the tray icon context menu
The Form code behind will look like this:
I then change the notifyicon mouse event to this (
TrayIconMenuForm
is the name of my Form for providing the context menu):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.
I'll occasionally use the Balloon Text in order to notify a user - that is done as such:
Nice little tutorial on using the NotifyIcon class here: http://www.developer.com/net/csharp/article.php/3336751