Thursday, August 5, 2010

Show Progressbar in Taskbar

From Windows 7 on upwards many new nice features come by, one of them being dynamic icons in the taskbar, which can express the state of the programs.
In this post I want to show you, how to show a progressbar in the program icon in the taskbar, which looks like this:

To create the progressbar, the Windows API Code Pack has to be installed.
If that is the case, we have to add 2 references to the desired project: Therefore select add reference and click Browse, then browse to the folder which contains the code pack.
Then further move to WindowsAPICodePack\Shell. Here our needed .dll files can be found, namely those are Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll.
Then we include the taskbar class in our project:

using Microsoft.WindowsAPICodePack.Taskbar;

The following code then produces a progressbar filled half, which is shown in the icon:

TaskbarManager tm = TaskbarManager.Instance;
tm.SetProgressValue(50, 100);

SetProgressState() determines the style of the application icon, we here tell the prorgamm to look "normal", so we can blend the progressbar over it.
Finally SetProgressValue() sets the progress of the bar, the first overgiven parameter is the current value of the progress, the second one the maximal one.

No comments:

Post a Comment