Click here to Skip to main content
15,390,470 members
Articles / Programming Languages / C#
Posted 19 May 2007


226 bookmarked

Fully themed Windows Vista Controls

Rate me:
Please Sign up or sign in to vote.
4.91/5 (60 votes)
16 Jun 2007Ms-PL9 min read
Render Windows Controls fully (with special fade effects) in Windows Vista


This article is about getting controls found in Windows Vista to make use of the new Windows Vista user interface. Included in the project are some components (Commandlinks, ImageButton, SplitButton) that work just like the Windows Vista themed controls.

The article would aim to achieve most of the interface effects (like the fade-in/out) effects seen throughout Windows Vista.


Most users of Windows Vista would probably notice the new user interface. Each control is a step nicer compared to that of Windows XP, and it comes complete with nice little fade effects. However, Microsoft Visual Studio does not support the full Vista themes by default. Although Visual Studio 2005 attempts to address the visual styles problem, it still does not allow controls to achieve all the visual effects seen throughout Windows Vista.

This article covers on:

  • Getting the fade effects on some common controls (Buttons, Checkboxes, Radiobuttons, Textboxes, Comboboxes)
  • Getting images working on Buttons, and preserving fade-effects
  • Getting the fade effects on Toolbars
  • Getting the Windows Vista theming on MainMenus and ContextMenus
  • Getting CommandLinks and SplitButtons
  • Getting different colored Progressbars
  • Getting the explorer-like interface for ListBoxes and TreeViews

It utilizes the user32.dll SendMessage() function, as well as the uxtheme.dll setwindowtheme() function for certain controls in order to render some of the controls to the desired level.


You will need the following things to complete this tutorial:

  • Windows Vista
  • .NET framework 2.0 (already preinstalled in Windows Vista)

Some other useful things (optional):

Common controls

Image 1

Most of the controls are already ready for the Windows Vista theming. I'm sure you have heard of EnableVisualStyles() right? EnableVisualStyles() is usually called to allow theme-aware controls to gain the user interface theme. While Visual Studio 2005 already has this done, Visual Studio 2003 does not have this on by default. If you want to enable theming for common controls, you can view Heath Steward's article on Windows XP Visual Styles for Windows Forms.

EnableVisualStyles() affects the following controls:

  • TextBox
  • RichTextBox
  • HScrollBar
  • VScrollBar
  • ProgressBar
  • TabControl (Partially)
  • MainMenu
  • ContextMenu
  • ComboBox
  • DataGrid
  • listBox
  • listView
  • TreeView
  • DateTimePicker
  • MonthCalendar
  • Splitter
  • TrackBar
  • StatusBar
  • ToolBar
  • TreeView
  • listView
  • Button
  • Groupbox (Partially)

While Visual Studio 2005 supports Visual Theming amongst controls, these controls do not have the "full" theme, which includes the fade effects. This problem can be addressed by setting FlatStyle to System. However, doing this means that images would not be displayed on such controls. This problem can be addressed fairly easily in the next section.

Getting images working on Buttons and other controls

By setting the button's FlatStyle to System makes buttons and some other images fail to display on these buttons. But, this section aims to address this problem, by using as little code as possible.

How to get this done? Well, we need to play around with the SendMessage() function found in user32.dll.

First, we would need to declare the function (but first, you will need to import System.Runtime.InteropServices):

//Imports the user32.dll
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage
            (IntPtr hWnd, int msg, int wParam, int lParam);

To set the image of a control, we will need to use the BM_SETIMAGE [0x00F7] message. For now, we would use an icon (Declared in System.Drawing) as an image, as it is easy to get a handle on the icon.

const int BM_SETIMAGE = 0x00F7;
private Icon buttonicon;
//Sets the button to use an icon
void SetImage()
    IntPtr iconHandle = IntPtr.Zero;

    // Get the icon's handle.
    if (this.buttonicon != null)
        iconHandle = this.Icon.Handle;

    //Sets the icon
    SendMessage(this.button1.Handle, BM_SETIMAGE, 1, (int)iconHandle);

What this code does is to retrieve the handle of the icon which you want to display on the button (called "button1"), and sends a message to Windows to set the button to use the icon.

You can set what icon you want by setting "buttonicon". You can do so by using the following code:

buttonicon = new Icon(SystemIcons.Exclamation, 40, 40);

This uses the system's exclamation icon. What you would get:

Image 2

If you would want to use a bitmap/image instead of an icon, you can use the GetHIcon() method from the Bitmap to retrieve the bitmap's handle and use the handle to set the button's image.

IntPtr iconhandle = IntPtr.Zero;
Bitmap image = new Bitmap("C:\images\an_image.png");
iconhandle = image_.GetHicon();
SendMessage(this.Handle, VistaConstants.BM_SETIMAGE, 1, (int)iconhandle);

This button still supports the fade effects other normal buttons have.

However, there is one small problem associated with using this method. If this button's text is set to "", no image would be displayed. This problem can be solved by using the createParams() function and assigning the BS_ICON theme to the button.

//CreateParams property
protected override CreateParams CreateParams
        CreateParams cParams = base.CreateParams;
        if (this.ShowIconOnly == true)
            //Render button without text
            cParams.Style |= 0x00000040; // BS_ICON value
    return cParams;

This method is best done from a class which is inherited from button.


CommandLinks are really just buttons, assigned with a different theme. Their themes and their values (taken from CommCtrl.h in the Windows Vista SDK) are as follows:

  • BS_COMMANDLINK [0x0000000E]

The first step would be to create a class inherited from button. Then, we can override the CreateParams() function to make the button use the respective theme. For the theme to take effect, you would need to set the button's flatstyle to system. Below is the class for the CommandLink:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices

public class CommandLink : Button
    const int BS_COMMANDLINK = 0x0000000E;

    //Set button's flatstyle to system
    public CommandLink()
        this.FlatStyle = FlatStyle.System;

    protected override CreateParams CreateParams
            CreateParams cParams = base.CreateParams;
            //Set the button to use Commandlink styles
            cParams.Style |= BS_COMMANDLINK;
            return cParams;

You can then build the project and use the component in your Windows Forms just like a normal button (since it is inherited from a normal button). The CommandLink looks like:

Image 3

*The mouse is over the CommandLink, but PrintScreen would not capture the mouse.

The button supports the fade effects just like the actual controls.

But wait? where's the CommandLink's "note"? Well, we can implement that feature by sending the BCM_SETNOTE [0x00001609] message to Windows. We can incorporate it into a property to set the note of the CommandLink with ease.

const uint BCM_SETNOTE = 0x00001609;
//Imports the user32.dll
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern IntPtr SendMessage
        (HandleRef hWnd, UInt32 Msg, IntPtr wParam, string lParam);
//Note property
private string note_ = "";
public string Note
        return this.note_;
        this.note_ = value;

//Sets the button's note
void SetNote(string NoteText)
    //Sets the note
    SendMessage(new HandleRef(this, this.Handle), 
                BCM_SETNOTE, IntPtr.Zero, NoteText);

You would get:

Image 4

You can also use the same method for showing icons/images on Buttons for CommandLinks:

Image 5


Image 6

Just like CommandLinks, SplitButtons are just simply buttons. You can set its style to that of the SplitButton's using the CreateParams method:

  • BS_SPLITBUTTON [0x0000000C]

However, even after setting the style, how are you going to associate a menu (contextmenu) to the button? We can do this by first associating an event which would be fired whenever a person clicks on the "dropdown" on the splitbutton. First, we would listen to all messages sent to the button by overriding the wndproc() method. It happens that the BCN_SETDROPDOWNSTATE [0x1606] message would be sent whenever the dropdown is clicked. This message is fired several times, but only one of the messages happen to be unique, with WPARAMS having the value of "1". The filtering of messages is best done within another class. This sample code would fire a custom event (DropDown_Clicked) whenever the dropdown is pushed.

protected override void WndProc(ref Message m)
    // Listen for operating system messages; 
    // Filter out a lot of messages here
    //The dropdown glyph changes:
    //Mousedown (at dropdown area) => Dropdown Event fired 
    //                => Glyph changes => MouseUp => Glyph Changes
    switch (m.Msg)
        case (VistaControls.VistaConstants.BCM_SETDROPDOWNSTATE):
        //PROBLEM: other buttons also have would encounter this message
        if (m.HWnd == this.Handle)
            ////This message seems to occur when the drop down is clicked; 
            ////Occurs several times, but one of them have the value of 1 
            ////in WParams
            if (m.WParam.ToString() == "1")

    base.WndProc(ref m);

Using this custom event, we can show a contextmenu whenever the dropdown part of the button is pressed (full code in the demo). This isn't all though. We have only assigned an event that would be fired whenever the Dropdown is pushed. We would need to make the dropdown glyph change at the right time. There are a few messages that we can use to achieve the correct painting of the glyphs. They are the WM_PAINT [0x0F], WM_LBUTTONDOWN [0x201], WM_MOUSELEAVE [0x2A3], WM_LBUTTONUP [0x202] and WM_KILLFOCUS [0x08] messages. We can run code whenever these messages are sent by overriding the WndProc() message. (The code is too messy to be placed here, but the full code can be found via the Windows Vista Controls Demo.)

Image 7

This control also supports the fade-effects.

Cue TextBoxes

Some TextBoxes in Windows Vista hint the user what they should type in (e.g. the search box). It usually appears as some grey text on the text box that would disappear when the user attempts to type things into the textbox. This feature is know as "cue banner". You can enable this feature on a textbox by using the EM_SETCUEBANNER [0x1501] message.

SendMessage(textbox1.Handle, 0x1500 + 1, IntPtr.Zero, 
                "Please type in something.");

Image 8

Mainmenus and Contextmenus

The default MainMenus (or MainMenuStrip) and ContextMenus (or ContextMenuStrip) in Visual Studio 2005 do not fully support the Windows Vista theme:

Image 9

Image 10

If you want to get the Windows Vista theme on your main menus and context menus, you would need to use the Visual Studio 2003 version, or the backwards compatible version on Visual Studio 2005 (Called "MainMenu" and "ContextMenu").

You can assign ContextMenus to controls using it's ContextMenu property (might be hidden in VB.NET in Visual Studio 2005).


While the default toolbars in Visual Studio 2005 do have the Windows Vista look (if the Rendermode is set to System), it does not have all of it. Most toolbars on Windows Vista have the fade effects. To get it, you will need to use the Visual Studio 2003 version or the backwards compatible version on Visual Studio 2005 (and above), and set its Appearance as Flat to get the fade effects.

Image 11

You can use ImageLists on toolbar buttons as well. For Toolbars to use the ImageList properly in Visual Studio 2003, call the applications.DoEvents() function after the application.EnableVisualStyles() function (Bugfix for Application.EnableVisualStyles Bug by Don Kackman).


In Windows Vista, progressbars come in different flavors, the most common progressbar being the green one. However, there are also the red and yellow versions as well (there is a blue version, known as a meter, but that is inaccessible). The progressbar colors seem to correspond to specific progressbar states. You can set these states using the PBM_SETSTATE [0x40F] message. The states are PBST_NORMAL [0x0001], PBST_ERROR [0x0002] and PBST_PAUSE [0x0003].

SendMessage(progressbar1.Handle, 0x400 + 16, 0x0001, 0); //Normal; Green
SendMessage(progressbar1.Handle, 0x400 + 16, 0x0002, 0); //Error; Red
SendMessage(progressbar1.Handle, 0x400 + 16, 0x0003, 0); //Pause; Yellow

Image 12

TreeViews and ListViews

By default, TreeViews and ListViews do not have the same look as that of Explorer:

Image 13

However, with a bit of code, you can make it look like this:

Image 14

You would need to use the SetWindowTheme() function found in the UXTheme.dll file. You can do this by using the following code:

//Imports the UXTheme DLL
[DllImport("uxtheme", CharSet = CharSet.Unicode)]
public extern static Int32 SetWindowTheme
        (IntPtr hWnd, String textSubAppName, String textSubIdList);

Then, you can set the relevant control to use the styles by using the following code:

SetWindowTheme(listView1.Handle, "explorer", null);

Where "listView1" is your ListView. You can do this for TreeViews as well.

But there is more. In Windows Explorer, these ListViews have the semi-transparent selection as well. You can do this by calling the LVS_EX_DOUBLEBUFFER [0x00010000] extended style.

SendMessage(listview1.Handle, 0x1000 + 54, 0x00010000, 0x00010000);

Image 15

Treeviews in Windows Explorer also have the fade effects. This can be achieved via the TVS_EX_FADEINOUTEXPANDOS [0x0040] extended style.

SendMessage(treeview1.Handle, 0x1100 + 44, 0x0040, 0x0040);

The treeviews also have the "auto-scroll" feature. You can enable this via the TVS_EX_AUTOHSCROLL [0x0020] extended style.

SendMessage(treeview1.Handle, 0x1100 + 44, 0x0020, 0x0020);

Points of Interest

There might be several messages or functions that can be used to modify the theme of controls that may not be found in the limited documentation on Windows Vista. Of course, it is kind of unusual that we have to use older versions of controls (like MainMenu and ContextMenu) in order to achieve the full potential of the new Windows Vista graphical user interface.

Things of note

I have not tested the above codes on Visual Studio 2003, nor have I run the application on Windows XP (I didn't make it backwards compatible "yet").

Some custom controls in the demo that may not work on legacy Windows versions are the CommandLinks, SplitButtons and ProgressBars.

It was tested in Visual Studio 2005 and Windows Vista.



  • Version 1.10: Jun 17 2007 - Several controls added/modified
  • Version 1.00: May 20 2007 - Initial


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Nicholas Kwan
Software Developer
Singapore Singapore
My other projects at Onfry

Comments and Discussions

QuestionVista progress bars seem to be "off by one" Pin
jeffb4228-Oct-14 19:26
Memberjeffb4228-Oct-14 19:26 
QuestionAwesome Work Pin
dipan chikani11-Sep-12 3:51
Memberdipan chikani11-Sep-12 3:51 
GeneralMy vote of 5 Pin
Member 799427326-Oct-11 17:23
MemberMember 799427326-Oct-11 17:23 
GeneralMy vote of 5 Pin
VallarasuS31-May-11 20:04
MemberVallarasuS31-May-11 20:04 
QuestionTrouble with CueTextBox Pin
jsdmj7-May-11 7:38
Memberjsdmj7-May-11 7:38 
GeneralVB.NET Pin
CeremBeyazit16-Apr-11 5:10
MemberCeremBeyazit16-Apr-11 5:10 
QuestionSetCompatibleTextRenderingDefault(false) not working for MenuStrip and ToolStripMenuItem Control Pin
sudhircn8321-Oct-10 1:09
Membersudhircn8321-Oct-10 1:09 
GeneralUse spesific theme Pin
BlackDogSpark22-Oct-09 6:44
MemberBlackDogSpark22-Oct-09 6:44 
GeneralListView corrected tricky Enter Event Pin
Der M21-Feb-09 11:28
MemberDer M21-Feb-09 11:28 
QuestionExplorerListView class Load event Pin
_Barry_10-Feb-09 1:22
Member_Barry_10-Feb-09 1:22 
GeneralExplorerListView - FullRowSelect [modified] Pin
Dave S. Anderson26-Jan-09 16:00
MemberDave S. Anderson26-Jan-09 16:00 
GeneralRe: ExplorerListView - FullRowSelect Pin
zicarius7-Feb-09 13:56
Memberzicarius7-Feb-09 13:56 
GeneralI've read the note, but.. Pin
harold aptroot20-Jan-09 2:41
Memberharold aptroot20-Jan-09 2:41 
GeneralRe: I've read the note, but.. Pin
Dave S. Anderson27-Jan-09 12:45
MemberDave S. Anderson27-Jan-09 12:45 
Generaldetailed listview without vertical lines [modified] Pin
Torbinho25-Oct-08 23:46
MemberTorbinho25-Oct-08 23:46 
QuestionVista Style Group/Sort anybody? Pin
Alexandru Stanciu27-Feb-08 17:57
MemberAlexandru Stanciu27-Feb-08 17:57 
GeneralRe: Vista Style Group/Sort anybody? [modified] Pin
Nicholas Kwan1-Mar-08 23:40
MemberNicholas Kwan1-Mar-08 23:40 
QuestionLicence Pin
Julian-w30-Dec-07 4:22
MemberJulian-w30-Dec-07 4:22 
GeneralRe: Licence Pin
Nicholas Kwan23-Feb-08 23:05
MemberNicholas Kwan23-Feb-08 23:05 
GeneralRe: Licence Pin
Julian-w23-Feb-08 23:09
MemberJulian-w23-Feb-08 23:09 
GeneralUsing icons on a Vista menu Pin
chaiguy133728-Dec-07 5:41
Memberchaiguy133728-Dec-07 5:41 
GeneralRe: Using icons on a Vista menu Pin
Nicholas Kwan23-Feb-08 23:11
MemberNicholas Kwan23-Feb-08 23:11 
AnswerUsing icons on a Vista menu (C# solution) Pin
Wyatt O'Day17-May-08 7:10
MemberWyatt O'Day17-May-08 7:10 
GeneralRe: Using icons on a Vista menu (C# solution) Pin
chaiguy133717-May-08 7:13
Memberchaiguy133717-May-08 7:13 
QuestionThanks! Any support for Task Dialogs? Pin
James Garner (jadaradix)26-Dec-07 22:11
MemberJames Garner (jadaradix)26-Dec-07 22:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.