Dear visitor, thanks for stopping by! If you want, you can follow all updates on via RSS. You can also follow me on Twitter or Facebook. More interesting posts from other Microsoft Regional Directors can be found at The Region.
Gill Cleeren     .net | C# | Programming     June 18, 2006    

For some time, I have been wondering how to create flashing, animated notify icons that appear in your taskbar. Windows has a lot of these, like for example MSN Messenger uses one when a person signs in. Or the flashing network icon when there is traffic going in or out.

I started thinking at first it used some kind of animated gif, but soon realized that that isn’t possible, since the NotifyIcon control in WinForms programs can only handle *.ico files or *.bmp files.

Now I found out how this actually works: the key element is the Timer control. It fires events at a regular interval, and what actually happens is that the icon is changed at these regular intervals.

To show “the magic”, I created a little demo-project.

First, create an array of icons:
private Icon[] icons = new Icon[4];

Then, load in the images. It’s actually creating an animated gif, only that now, you have to programmatically change between the steps.

icons[0] = new Icon("green.ico");
icons[1] = new Icon("red.ico");
icons[2] = new Icon("green.ico");
icons[3] = new Icon("red.ico");

Add a NotifyIcon and a Timer control to your program. Set the timer to an interval of 1000 (that is milliseconds).

Now, create the Tick event of the timer, to fire the event that will change the icon displayed in the NotifyIcon.
Since we have loaded the icons in an array, all we have to do is change the index in the array, and update the icon in the NotifyIcon accordingly.

private void timerChangeIcons_Tick(object sender, EventArgs e)
   animatedIcon.Icon = icons[currentIcon];
      if (currentIcon == 4)
         currentIcon = 0;

Don’t forget to add the timer.Start() to the load of your form!

I did however notice something strange in the behavior of C#. It appears that icons created with for example PhotoShop or Paint throw an error when loaded: "Argument 'picture' must be a picture that can be used as a Icon”. This appears that have been a problem already in C# 1.0 and it is not addressed under C# 2.0.
To correctly display the created icons, you have to change the headers, based on Windows API documentation.
A workaround I found, is simply to open the icons in Visual Studio and save them again. This worked correctly afterwards.

The complete code can be found in the zip-file. (14.98 KB)

kick it on
  Posted on: Sunday, June 18, 2006 12:13:28 PM (Romance Daylight Time, UTC+02:00)   |   Comments [0] Tracked by:
"Winforms how-to: Dynamically changing the icon shown in the taskbar " (dotnetki... [Trackback]

5/28/2015   9:49:25 AM
 Welcome to
Hello and welcome to!

My name is Gill Cleeren, I'm a Microsoft Regional Director and an MVP ASP.NET.
On, you'll find all kind news and articles on .net, ASP.NET, WPF, Silverlight and Microsoft in general.
More on me can be found on my about page.

Should you have any questions, don't hesitate to contact me by Send mail to the author(s) .

 Partner sites
 Most popular tags
.net (124) .net 3.0 (6) .net 3.5 (18) .NET 4 (18) .NET Show (1) (4) (53) AJAX (4) ASP.NET MVC (3) Atlas (12) Azure (2) Blend (2) Book (6) Book review (4) C# (43) Case studies (1) Chopsticks (3) Community (10) Community Day (16) Consoles (1) Database (1) DevDays09 (4) DotNetNuke (4) Efficiency (57) Enterprise Library (5) Events (62) Expression (7) Games (3) Hardware (9) Internet (18) IT (1) jQuery (1) LightSwitch (3) Links (11) LINQ (4) Mac (2) Metro (1) Microsoft (75) Mix 07 (6) Mix 08 (4) Mix 09 (1) Mix 11 (1) Movies (4) MVP (5) MVP Summit 2008 (3) mvvm (1) NDCOslo (1) Office 2007 (10) Other (8) PDC (22) PDC2008 (10) Personal (36) ppt (9) Programming (52) Programming tools (22) Regional Director (2) Silverlight (143) Silverlight Advent Calendar (24) sl4 (44) SL5 Data and Services Cookbook (2) Slide decks (13) Snowball (13) Software (20) Microsoft (25) Speaking (15) SQL Server (10) TechDays (13) TechEd (14) telerik (6) Telerik (6) TFS (1) Twitter (1) Vista (73) Vista Tricks (9) Visual (38) Visug (33) VS2010 (8) Wallpaper (2) WCF (2) Webcasts (9) Webinars (5) Windows (41) Windows 7 (5) Windows 8 (3) Windows Azure (2) Windows Mobile (3) Windows Phone 7 (2) WinFX (17) WinRT (2) WP7 (2) WPF (40) XAML (24)

 On this page
 This site
 Blogroll OPML

All content is property of Nothing on this site can be copied or published elsewhere, unless otherwise stated.

This site is made by Gill Cleeren.

Questions? Opinions? Send mail to the author(s) E-mail