Thumbnail toolbars in .NET

DZone 's Guide to

Thumbnail toolbars in .NET

· ·
Free Resource

Windows 7 introduced many new UI elements as component parts of the overall Windows GUI. Most of those are somehow connected to the new Windows 7 taskbar. One of these elements is called Thumbnail toolbar  and it is a toolbar that is shown in the window thumbnail, when the user puts the mouse over its icon in the taskbar. This element is already used in many applications that are designed to run on Windows 7. Here are some examples.

Microsoft Zune Software:

Apple iTunes:

A Thumbnail toolbar can simplify access to the most used application features. As seen in the examples above, the most common actions for media applications are connected with media playback – play, pause, go to next item, return to the previous item and favorite a specific item.

Similar functionality can be easily introduced in a .NET application with the help of Windows API Code Pack for .NET Framework. First of all, I needed to add the proper references to my WinForms .NET application (the method described here can be easily applied in a WPF application as well). Those included the following (all of them are required):

Microsoft.WindowsAPICodePack.dll (from Windows API Code Pack)
Microsoft.WindowsAPICodePack.Shell.dll (also comes from the Windows API Code Pack)

Every button that is going to be created in the Thumbnail toolbar is an instance of ThumbnailToolbarButton, therefore I am going to create one just the way I am instantiating any other class:

ThumbnailToolbarButton button = new ThumbnailToolbarButton(new Icon("D:\\sample.ico",16,16), "Sample");

button.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(button_Click);

Note that I am also adding an event handler for the Click event. This is how the event handler itself looks like:

void button_Click(object sender, ThumbnailButtonClickedEventArgs e)
MessageBox.Show("This comes from the thumbnail!");

It is possible to put any action tied to the application here, just like in any other event handler.

The first parameter passed to the new instance of ThumbnailToolbarButton is an instance of Icon – it opens a ICO (Windows Icon) file, sets the width and height to 16 pixels and is used as the icon for the button. The second parameter is the tool tip for the button.

I recommend putting the button initialization code right after InitializeComponent(), so that it creates the toolbar the moment the application starts, unless you want it to behave in some other way. But the code above is not going to work yet, because the current instance of Taskbar did not receive the information about the buttons that are going to be displayed in the Thumbnail toolbar. To fix this, I added:


TaskbarManager.Instance.ThumbnailToolbars.AddButtons(this.Handle, button);

The first parameter must be the window handle, while the second is an array of ThumbnailToolbarButton. You can pass several  buttons there, separated with a comma.

Now, when I run the application and point the mouse cursor over the application icon in the taskbar, I see this:

When I click the button, I get a MessageBox:


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}