Click here to Skip to main content
13,834,141 members
Click here to Skip to main content
Add your own
alternative version


76 bookmarked
Posted 8 Jul 2008
Licenced CPOL

Minimize window to system tray

, 8 Jul 2008
Rate this:
Please Sign up or sign in to vote.
This article describes how you can write some simple code for minimizing a window to the system tray.


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.

  1. Create a new Windows Application project using Visual Studio.
  2. You’ll have a default Form opened up for you. From the Toolbox, add a NotifyIcon control to your form.
  3. 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:
    • Check whether the form’s WindowState property is set to FormWindowState.Minimized.
    • If yes, hide your form, enable the NotifyIcon object, and show the balloon tip that shows some information.
    • Once the WindowState becomes FormWindowState.Normal, disable the NotifyIcon object by setting its Visible property to false.
  4. Now, you want the window to reappear when you double click on the NotifyIcon object in the taskbar. For this, handle the NotifyIcon’s MouseDoubleClick event. Here, you show the form using the Show() method.

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:

//  The NotifyIcon object
private System.Windows.Forms.NotifyIcon notifyIcon1;
this.notifyIcon1.Icon = 

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...


Comments and Discussions

Suggestionfirst hide notifyIcon Pin
Pran Krishna Das18-Feb-15 5:38
memberPran Krishna Das18-Feb-15 5:38 
GeneralMy vote of 5 Pin
Abhishek Pant24-Oct-12 7:56
professionalAbhishek Pant24-Oct-12 7:56 
QuestionThis code is not working in VS2010. How to make it work ? Pin
Member 915755722-Jun-12 19:30
memberMember 915755722-Jun-12 19:30 
AnswerRe: This code is not working in VS2010. How to make it work ? Pin
HBeaudry13-Jul-12 4:17
memberHBeaudry13-Jul-12 4:17 
GeneralMy vote of 5 Pin
Member 105108228-Jun-12 9:43
professionalMember 105108228-Jun-12 9:43 
QuestionRe: My vote of 5 Pin
Member 915755722-Jun-12 19:49
memberMember 915755722-Jun-12 19:49 
GeneralMy vote of 5 Pin
sixthplanet4-Apr-12 23:29
membersixthplanet4-Apr-12 23:29 
GeneralThank you! Pin
Cosmin Serban20-Jan-12 23:34
memberCosmin Serban20-Jan-12 23:34 
QuestionThank you! +5 Pin
jclark239b96-Dec-11 10:32
memberjclark239b96-Dec-11 10:32 
QuestionI follow exactly all your coding, but it still does not minimize to tray, Any reason why? Pin
Ken Than13-Jul-11 22:01
memberKen Than13-Jul-11 22:01 
GeneralRe: I follow exactly all your coding, but it still does not minimize to tray, Any reason why? Pin
Member 915755722-Jun-12 19:40
memberMember 915755722-Jun-12 19:40 
SuggestionRe: I follow exactly all your coding, but it still does not minimize to tray, Any reason why? Pin
Abhishek Pant24-Oct-12 7:55
professionalAbhishek Pant24-Oct-12 7:55 
GeneralMy vote of 5 Pin
Member 80638418-Jul-11 10:13
memberMember 80638418-Jul-11 10:13 
QuestionRe: My vote of 5 Pin
Member 915755722-Jun-12 19:42
memberMember 915755722-Jun-12 19:42 
GeneralMy vote of 5 Pin
saba_aravind1-Nov-10 6:51
membersaba_aravind1-Nov-10 6:51 
GeneralRestoring maximized state, Pin
Vozzie26-Sep-09 5:41
memberVozzie26-Sep-09 5:41 
GeneralRe: Restoring maximized state, Pin
guibirow2-Jul-13 20:12
memberguibirow2-Jul-13 20:12 
GeneralRe: Restoring maximized state, Pin
Vozzie230-Oct-13 17:33
memberVozzie230-Oct-13 17:33 
Generalquestion Pin
maditude29-Mar-09 16:23
membermaditude29-Mar-09 16:23 
GeneralRe: question Pin
Elroy Dsilva6-Sep-09 5:52
memberElroy Dsilva6-Sep-09 5:52 
GeneralRe: question Pin
jclark239b96-Dec-11 10:31
memberjclark239b96-Dec-11 10:31 
GeneralGood job Pin
danzar19-Dec-08 18:27
memberdanzar19-Dec-08 18:27 
GeneralSwitch Pin
PIEBALDconsult8-Jul-08 7:42
protectorPIEBALDconsult8-Jul-08 7:42 
GeneralRe: Switch PinPopular
Elroy Dsilva8-Jul-08 7:52
memberElroy Dsilva8-Jul-08 7:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190114.1 | Last Updated 8 Jul 2008
Article Copyright 2008 by Elroy Dsilva
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid