This time we will talk about another feature of the Windows 7 taskbar - OverlayIcon. This feature is extremely useful for applications that have some state from the user's point of view.
These applications include instant messaging (IM) programs. For example, Windows Live Messanger is actively using this feature. For example, if we open WLM and change the state, then you can see how it is displayed on the taskbar.
')
Such functionality can be useful for a variety of applications. Fortunately, implementing it is not so difficult. As in the previous examples, we will use the
.NET Interop Sample Library .
To add a status icon to the main application icon, you need to add a resource file to the project and place the necessary icons there. Also, we can get Icon objects from another place, if necessary.
Now all that needs to be done is to use extension methods that allow us to set icons for our application. For these purposes, the SetTaskbarOverlayIcon method is defined. We must give him in the parameters of our form, icon and description. Thus, installing a new icon from the code will look like this.
WindowsFormsExtensions.SetTaskbarOverlayIcon(this, Icons.Error, "Error");
We can also remove this icon. To do this, pass the value null instead of the icon itself.
WindowsFormsExtensions.SetTaskbarOverlayIcon(this, null, String.Empty);
Let's create for example a small application in which we can switch the state. It will look like this.
Clicking on each of the buttons switches the status that is displayed in the taskbar.
Demo application:
Taskbar-Icons.zip