Minimizing a window to the system tray makes your application somewhat cool, isn’t it? This functionality can be really useful when you want to run an application in the background, for example, chat applications, anti-viruses, and programs that monitor the state of your machine.
This article requires you to have basic knowledge of programming Windows Forms in C#.
Using the Code
Now, let’s see what we need to include this functionality in any Windows application. There are a few very simple steps towards achieving this.
- Create a new Windows Application project using Visual Studio.
- You’ll have a default
Form opened up for you. From the Toolbox, add a
NotifyIcon control to your form.
- Handle the form’s
Resize event. In this handler, you override the basic functionality of the
Resize event to make the form minimize to the system tray and not to the taskbar. This can be done by doing the following in your form’s
Resize event handler:
Now, you want the window to reappear when you double click on the
- Check whether the form’s
WindowState property is set to
- If yes, hide your form, enable the
NotifyIcon object, and show the balloon tip that shows some information.
- Once the
FormWindowState.Normal, disable the
NotifyIcon object by setting its
Visible property to
NotifyIcon object in the taskbar. For this, handle the
MouseDoubleClick event. Here, you show the form using the
Remember to set the
notifyIcon1.Icon property to a valid
Icon resource object; otherwise, the system tray will not show any icon, and your window will never return to the foreground.
I have added some code below to get things started:
private System.Windows.Forms.NotifyIcon notifyIcon1;
private void TrayMinimizerForm_Resize(object sender, EventArgs e)
notifyIcon1.BalloonTipTitle = "Minimize to Tray App";
notifyIcon1.BalloonTipText = "You have successfully minimized your form.";
if (FormWindowState.Minimized == this.WindowState)
notifyIcon1.Visible = true;
else if (FormWindowState.Normal == this.WindowState)
notifyIcon1.Visible = false;
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
this.WindowState = FormWindowState.Normal;
Points of Interest
Some window applications need to stay running as long as the computer is on; for example, Microsoft Outlook, Yahoo chat etc., need to run all the time unless they are explicitly terminated. This concept of minimizing windows to the system tray is very helpful when too many open windows crowd up the taskbar.
Elroy is a software developer whose technical experitise and learning include programming languages such as C, C++ and C#. He loves writing simple technical articles and blogging whenever He finds some time for himself.