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(this, null, 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.