Tray Bar Application


This is a very simple C# application which implements those very familiar Windows applications with a tray Icon . To implement this application I used C# and VS.NET beta 2.

First, create a new Windows Application on VS.NET. In the automatically added Form set the property ShowInTaskBar to false and WindowsState property as Minimized.

Add a NotifyIcon and a ContextMenu Control to your form. In the ContextMenu Control add two MenuItem and set the Text property of each one to Hello and Exit respectively.

For the NotifyIcon control that you have just added to the form you must set the property Icon to any *.ico file in your file system.

Now add code to the events on click of every MenuItem of the context Menu:

private void menuItem1_Click(object sender, System.EventArgs e)
MessageBox.Show("Hello World. This a tray icon application. Bye!");
private void menuItem2_Click(object sender, System.EventArgs e)
// exits the application

The context menu should be poped up by your application when you click the right button of the mouse over the tray icon that will appear once you execute the application. The combination of the properties, WindowsState as Minimized and the ShowInTaskBar as false, avoid that your application appears in the Task Bar and the main form is minimized when the application starts. In this way, the only thing that is visible to the application user is the Windows tray icon.

That's it. Compile the source code and enjoy it!

Similar Articles