DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

Tabbed thumbnails in .NET

Denzel D. user avatar by
Denzel D.
·
Apr. 15, 10 · Interview
Like (0)
Save
Tweet
Share
8.15K Views

Join the DZone community and get the full member experience.

Join For Free

Tabbed thumbnails were introduced in Windows 7 with the new taskbar. If an application supports tabbed thumbnails, then, if a user points the mouse over the app icon in the taskbar, while the application is running, he is able to view multiple instances of various application controls opened in several tabs above the taskbar.
The most obvious example in this case would be Internet Explorer 8. If the user opens multiple tabs with various content on them, he can switch between them by pointing the mouse cursor over the IE icon in the taskbar.
 

By default, .NET WinForms applications, be those MDI or TDI do not get support for tabbed thumbnails. To achieve this, either the native API is used, or a managed wrapper, like Windows API Code Pack. The reason behind this lies in DWM – Desktop Window Manager, the graphical user interface subsystem in Windows 7. It is only able to directly communicate with top-level windows (main window for an application) and not with child windows or controls.


The API wrapper provides the functionality to get over this limitation. To test it, I created a standard WinForms application with a button and a label on it. I added references to PresentationCore, WindowsBase, Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll (the last two are included in the Windows API Code Pack). If I run the application now, the default thumbnail preview looks like this:
 


What if I wanted to create a thumbnail preview for each control on the form? Basically, to achieve this, all I have to do is create separate instances of TabbedThumbnail, set the specific properties (if I want to customize the default view) and add it to the taskbar instance.
For my specific sample application, this is achieved by doing this:
TabbedThumbnail[] thumbnails;

thumbnails = new TabbedThumbnail[this.Controls.Count];

for (int i = 0; i < this.Controls.Count; i++)
{
thumbnails[i] = new TabbedThumbnail(this.Handle, this.Controls[i]);
thumbnails[i].Title = this.Controls[i].ToString();
}

foreach (TabbedThumbnail thumbnail in thumbnails)
TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(thumbnail);


I am iterating through the control array on my form and creating an instance of TabbedThumbnail for each found control. Notice the fact that each tabbed thumbnail also gets the current window handle. The Title property will represent (in this case) the type of the control. When the array is completely populated, I am adding each TabbedThumbnail to the taskbar instance. It looks like this:



But the functionality of tabbed thumbnails isn’t only limited to previews. What if I want to create a custom event that will be triggered once the user clicks on a tab? To do this, I add this code in the control iteration loop:

thumbnails[i].TabbedThumbnailActivated += new EventHandler<TabbedThumbnailEventArgs>(Form1_TabbedThumbnailActivated);

The event handler itself looks like this:

void Form1_TabbedThumbnailActivated(object sender, TabbedThumbnailEventArgs e)
{
this.Text = "Changed";
}


It doesn’t do anything important – just changes the main form’s Text property. However, a developer can customize this event as needed.
The entire set of event handlers for an instance of TabbedThumbnail is shown below:
 


application

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Submit a Post to DZone
  • The Path From APIs to Containers
  • REST vs. Messaging for Microservices
  • HTTP vs Messaging for Microservices Communications

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: