What do I need to do to make a Windows Forms application run in the System Tray?
Not an application that can minimize to the tray, but one that exists only in the tray, with nothing more than an icon, tool tip, and "right click" menu.
What do I need to do to make a Windows Forms application run in the System Tray?
Not an application that can minimize to the tray, but one that exists only in the tray, with nothing more than an icon, tool tip, and "right click" menu.
The code project article Creating a Tasktray Application gives a very simple explanation and example of creating an application that only ever exists in the System Tray.
Basically change the
Application.Run(new Form1());
line inProgram.cs
to instead start up a class that inherits fromApplicationContext
, and have the constructor for that class initialize aNotifyIcon
It is very friendly framework for Notification Area Application... it is enough to add NotificationIcon to base form and change auto-generated code to code below:
"System tray" application is just a regular win forms application, only difference is that it creates a icon in windows system tray area. In order to create sys.tray icon use NotifyIcon component , you can find it in Toolbox(Common controls), and modify it's properties: Icon, tool tip. Also it enables you to handle mouse click and double click messages.
And One more thing , in order to achieve look and feels or standard tray app. add followinf lines on your main form show event:
I've wrote a traybar app with .NET 1.1 and I didn't need a form.
First of all, set the startup object of the project as a Sub
Main
, defined in a module.Then create programmatically the components: the
NotifyIcon
andContextMenu
.Be sure to include a
MenuItem
"Quit" or similar.Bind the
ContextMenu
to theNotifyIcon
.Invoke
Application.Run()
.In the event handler for the Quit
MenuItem
be sure to call setNotifyIcon.Visible = False
, thenApplication.Exit()
. Add what you need to theContextMenu
and handle properly :)Here is how I did it with Visual Studio 2010, .NET 4
As mat1t says - you need to add a NotifyIcon to your application and then use something like the following code to set the tooltip and context menu:
This code shows the icon in the system tray only:
The following will be needed if you have a form (for whatever reason):
The right click to get the context menu is handled automatically, but if you want to do some action on a left click you'll need to add a Click handler: