📜 ⬆️ ⬇️

We program Windows 7: Taskbar. Part 4 - Custom OverlayIcon

Earlier, I wrote about how you can add a status icon for your application in the Windows 7 taskbar. We looked at static images for this purpose. Let me remind you that for this we used the SetTaskbarOverlayIcon method, in the parameters of which the Icon link is passed.

However, one of the blog readers suggested another scenario in which some information is displayed at the place of the additional icon. For example, this may be the current download speed, if your software downloads something over the network. Or it may be the number of new letters in the mailbox, if it is an email client. Examples can lead a lot.

Let me remind you that in order to set a static image, you must run the following code.
')
WindowsFormsExtensions.SetTaskbarOverlayIcon(this, Icons.Error, "Error");

As a second parameter, an Icon object is passed here. However, who prevents us from generating this object dynamically? Let's use the uncomplicated code and do it. I will create a method that will generate such an image and show this icon.

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, using the BuildIcon method, a new icon will be generated, which will be displayed on the taskbar.



In this screenshot, you can clearly see that we have added text to the standard icon and displayed it on the taskbar.

In the demo application, I created a timer that mimics the work of the download manager, producing constantly different download speeds.

Demo application:
Taskbar-CustomIcons.zip

Source: https://habr.com/ru/post/60358/


All Articles