Click here to Skip to main content
13,558,244 members
Click here to Skip to main content
Add your own
alternative version


85 bookmarked
Posted 13 Dec 2005
Licenced CPOL

Notify Icon control in .NET 2.0 with balloon tips

, 13 Dec 2005
Rate this:
Please Sign up or sign in to vote.
This article shows how to use the new notify icon control along with the new balloon tip properties.

Sample Image - NotifyIconControl20.gif


In previous versions of .NET, if you wanted to have a notify icon in the tray, you had to use the notify icon class and do a little extra work. Now, in .NET 2.0, there is a notify icon control that you can drop on to your Windows form. One nice thing that has been added is the balloon tip properties.


I had just written an article on using Windows messaging to cause an existing instance of an application to show up even if it was minimized or hidden, like in a tray icon. So, I was doing a little investigation to see what was different in .NET 2.0. That’s when I saw the notify icon control and decided to play with it. I don’t currently have any application in production that uses this code, but I think sometime soon I probably will.

The Problem

You may ask, why use a notify icon at all? I guess the answer that comes to mind is so that you can see your application in the tray. In my example, when the application is minimized, I hide the form from the task bar.

Note: There is a new property on the form that you can use if you don’t ever want the form to show up in the task bar. It is called “ShowInTaskBar”. If you set this property to false, the app will not show up in the task bar.

This app hides the form from the task bar on minimize and shows it when it is not minimized. A problem with using the tray is users can get confused and not know where the application went. Especially, when you hide the form from the task bar like this app is doing. So, the solution here is to use the balloon tip. It is a nice feature that allows you to display a little balloon message above the tray icon when certain things happen.

The Solution

This app displays this balloon tip message when you minimize the form.

Balloon tip on minimize of the form

Next, this app displays this balloon tip message when you click the X in the upper right hand corner. This is similar to what the Windows Messenger does.

Note: I am not a big fan of overwriting the click on the x in the upper right hand corner from its default functionality which is to close the app, but I thought I would do it in this app for an example.

This balloon tip shows when the user clicks the X in the upper right hand corner

The Code

Here is the code that checks the current Windows state so we know if we should hide or show the form on the task bar:

private void Form1_Move(object sender, EventArgs e)
  //This code causes the form to not show up on the task bar only in the tray.
  //NOTE there is now a form property that will allow you to keep the 
  //application from every showing up in the task bar.
  if (this == null)
  { //This happen on create.
  //If we are minimizing the form then hide it so it doesn't show up on the 
  //task bar
  if (this.WindowState == FormWindowState.Minimized)
    notifyIcon1.ShowBalloonTip(3000, "Test App",
            "The App has be moved to the tray.",
  {//any other windows state show it.


Here is the code that checks when the form is closing to see if we will really close the app or just send it to the tray:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  //There are several ways to close an application.
  //We are trying to find the click of the X in the upper right hand corner
  //We will only allow the closing of this app if it is minimized.
  if (this.WindowState != FormWindowState.Minimized)
    //we don't close the app...
    e.Cancel = true;
    //minimize the app and then display a message to the user so
    //they understand they didn't close the app they just sent it to the tray.
    this.WindowState = FormWindowState.Minimized;
    //Show the message.
    notifyIcon1.ShowBalloonTip(3000, "Test App",
         "You have not closed this appliation."+
         (Char)(13)+"It has be moved to the tray."+
         (Char)(13)+"Right click the Icon to exit.",

Here is the code which runs when you double click the tray icon to bring it back to the normal Windows state:

private void notifyIcon1_DoubleClick(object sender, EventArgs e)
  if (this.WindowState == FormWindowState.Minimized)
    this.WindowState = FormWindowState.Normal;

  // Activate the form.


Hopefully, this article showed you how to use the new notify icon control and the balloon tip that comes with it. I hope you find this information useful.


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


About the Author

Software Developer (Senior)
United States United States
I started my programmer career over 21 years ago doing COBOL and SAS on a MVS mainframe. It didn't take long for me to move into windows programming. I started my windows programming in Delphi (Pascal) with a Microsoft SQL server back end. I started working with when the beta 2 came out in 2001. After spending most of my programming life as a windows programmer I started to check out in 2004. I achieved my in April 2005. I have done a lot of MS SQL database stuff. I have a lot of experience with Window Service and Web services as well. I spent three years as a consultant programing in C#. I really enjoyed it and found the switch between and C# to be mostly syntax. In my current position I am programming in C# working on WPF and MSSql database stuff. Lately I have been using VS2015.

On a personal note I am a born again Christian, if anyone has any questions about what it means to have a right relationship with God or if you have questions about who Jesus Christ is, send me an e-mail. ben.kubicek[at]netzero[dot]com You need to replace the [at] with @ and [dot] with . for the email to work. My relationship with God gives purpose and meaning to my life.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
cngirwa6-Jan-13 2:06
membercngirwa6-Jan-13 2:06 
GeneralRe: My vote of 5 Pin
S.M. Zamshed Farhan22-Jan-13 17:31
memberS.M. Zamshed Farhan22-Jan-13 17:31 

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 | Terms of Use | Mobile
Web03-2016 | 2.8.180515.1 | Last Updated 13 Dec 2005
Article Copyright 2005 by kubben
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid