How to Create a Tray Icon
A tray icon is a part of an application that inserts an icon in the system tray when the user clicks the minimize button. This form of usability allows the user to run the application in the background. It also provides an easy way for the user to return to the application without using Windows menus.
Instructions
-
-
1
Drag and drop a "NotifyIcon" control from the Visual Studio toolbar to the form of your program. This creates an instance of the control and its methods and properties can be used in the application.
-
2
Edit the event handler that captures the "minimize" action from the user. The "Hide()" function minimizes the program to the taskbar.
private void myForm_Resize(object sender, System.EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
Hide(); //hide the form and minimize to the taskbar
} -
-
3
Create the event that handles a double-click on the tray icon. The user needs to maximize the window after the user clicks the icon. The following code calls the "Show" function.
private void myNotify_DoubleClick(object sender, System.EventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
} -
4
Build the program to test the new code entries. Minimize the window and double-click the tray icon to verify the code is working.
-
1