Friday, December 26, 2008

How to Make System Tray Based Application in .NET

How to Make System Tray Based Application in .NET

Creating an application that lives in the system tray is easy, but it is not entirely obvious how to do so in Visual Studio. This recipe will show you the steps.

1) First, create a new Windows Application project in Visual Studio.NET. This can be either Visual Basic or C#

2) Drag a Notifyicon control and a ContextMenu control from the toolbox onto the form.

3) Click on the NotifyIcon control that you just added, and set the Icon property to whatever icon you want your application to have.

4) Set the ContextMenu property of the Notifyicon to the context menu that you added to your project.

5) Right click on the Context Menu control, and select Edit. Since this menu will be the right-click menu for your tray icon, you will want to add the items that the user will see. Make sure to add an Exit menu item.

6) Double click the Exit menu item, and add the following code:

7) Now for the important settings. Click on the form, and go to the Properties window. Set the following settings:

FormBorderSize: Fixed Tool Window
WindowState: Minimized
Opacity: 0%
ShowInTaskbar: False

The key thing to remember is that the default form is not to be used for application functionality, it is only used as the hidden background window. If you want to create a new window, you can just add another form to your application.

1 comment:

ZOverLord said...

Please see this example as well Click Here