Developing with the Taskbar in Windows 7
page 5 of 7
by Sergey Zwezdin
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 24843/ 75

Overlay icons

This possibility is useful if applications have any state from a user point of view. As example of such, applications can be programs for instant messages. For instance, Windows Live Messenger uses this possibility. If you open Windows Live Messenger and change a state, you can see how it is displayed on the task panel.

Figure 4: Overlay icons of Windows Live Messenger

To add a state icon to the main icon of the application, it is necessary to add a resource file in the project and to place there the necessary icons. Also, it is possible to receive Icon objects from another place if it is necessary.

Now you need to use methods of expansion that allows us to set icons for our application. For these purposes SetTaskbarOverlayIcon method is defined. As parameters of this method we should pass our form, an icon and description. Thus, code of a new icon setting up is like the following.

Listing 6: Setting up overlay icon

WindowsFormsExtensions.SetTaskbarOverlayIcon(this, Icons.Error, "Error");

Also, it is possible to remove this icon. For this purpose it is necessary to pass null value instead of the icon.

Listing 7: Clearing overlay icon

WindowsFormsExtensions.SetTaskbarOverlayIcon(thisnull, String.Empty);

You can also imagine another scenario where, instead of an additional icon, any information can be displayed. For example, it can be the current download speed if your software downloads something from a network. Or it can be quantity of new letters in a mail box if it is a mail client.

As the second parameter in SetTaskbarOverlayIcon method object Icon is passed, it is possible to generate this object dynamically. Let us take advantage of a simple code and do it. We will create a method which will generate such an image.

Listing 8: Generating icon dynamically

private static Icon BuildIcon(int param)
{
    Bitmap image = Icons.BLANK2334242;
    Graphics.FromImage(image).DrawString(param.ToString(@"D2"), 
        new Font("Arial", 54), Brushes.White, 10, 25);
    return Icon.FromHandle(image.GetHicon());
}
 
private void ShowStatus(object sender, EventArgs e)
{
    WindowsFormsExtensions.SetTaskbarOverlayIcon(this, BuildIcon(50, "Status");
}

Thus, thanks to BuildIcon method, a new icon which will be generated and displayed on the task panel.

In this example you can see that a text was added to a standard icon and the result was displayed on the task panel. In this demonstration application there is a timer which simulates the work of a download manager, giving out different "speeds" of downloading constantly.


View Entire Article

User Comments

Title: Source Code & Windows 7 Lib   
Name: Willy
Date: 1/13/2011 9:07:34 PM
Comment:
hi sergey, your article is amazing
please send me the source code, I need to improved my application, email me at skylancer3id@yahoo.com

I wonder where is download the windows 7 library for C# visual studio .net 2008, my application running on it.

many thanks.
Willy
Title: Re: Attach Full Source Code   
Name: Sergey Zwezdin
Date: 3/8/2010 12:54:15 AM
Comment:
Ashish, send me mail-request, please?
sergey@zwezdin.com
Title: Attach Full Source Code   
Name: Ashish Kumar
Date: 3/7/2010 3:26:16 AM
Comment:
hi...
please attach full source code with this article.
please.........
Title: reviews   
Name: r4 dsi
Date: 11/30/2009 5:43:34 AM
Comment:
Windows 7 is more than what Vista should have been, it's where Microsoft needed to go. How much damage Vista did and whether Windows 7 is enough for people to finally abandon Windows XP are questions that nobody has the answers to right now.
Title: Amazing !   
Name: Aamod Thakur
Date: 11/6/2009 4:15:19 AM
Comment:
Amazing Article, Very Informative.

Thanks Sergey

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 7/25/2014 6:18:02 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search