Hethu's Techno Babble

Monday, August 29, 2005

Minimize to Tray (Notification Area) and show Balloon Notifications in C#

I have been searching the web for quite a while for a .NET class that can do the minimize to tray animation and show balloon notifications in the notification area.

It is quite easy to make an .NET application show a notification icon in the taskbar notification area with the built in NotifyIcon .NET control. But it is not possible to show a balloon notification message like the one you see when you plug in a USB device, or the one that reminds you of "Files waiting to be written to CD". Also, the built-in NotifyIcon control doesn't allow you to do the window minimize animation onto the notify icon area as it should. Why have Microsoft not exposed these Win32 functionality to the .NET 1.1 control?

(By the way, there is no such thing called the System Tray, it is officially called the Taskbar Notification Area, but most people still call it the Tray)

If you want to do a minimize to tray, your best bet is to set Form.ShowInTaskbar=false; and show the NotifyIcon. But this results in an ugly and a bad minimize animation. The window appears to minimize to the taskbar area and disappears into thin air, and then suddenly the icon appears in the notification area out of the blue. That isn't right.

There are several CodeProject articles giving ways to do this properly. But the best implementation I have found yet is by Matt Griffith in his .NET utilities class library. His NotifyIcon class can do the following:

  1. Show the notification area icon and tooltip
  2. Minimize to Tray with window animation
  3. Restore from Tray with window animation
  4. Show balloon notifications in the notification area (cool!) until a given timeout

The class library is very well documented. Unfortunately no code samples are given but it's quite easy to figure it out.

206 Comments: