Click here to Skip to main content
13,288,520 members (77,743 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 29 May 2008

How to Disable Windows Themes Using uxtheme.dll and SetWindowTheme

, 17 Jul 2008
Rate this:
Please Sign up or sign in to vote.
How to disable Windows themes to ensure uniform application appearance acrross all versions of Windows.



This article explains how to disable Windows themes in a .NET application to ensure uniform appearance across all versions of Windows.


A few months ago, it has come to my attention that Windows will paint forms and controls differently depending on the current Windows Theme that is active on the user's PC.

This does not end at a different window style or status bar, but actual colors painted differently. For example, Color.Silver will look much lighter in the Windows XP theme than it would in Windows Classic. Under Windows Vista, Color.Silver is almost white. Some colors disappear completely under Vista, and are painted as white.

So began my search for a way of turning off Windows themes in a .NET applications to allow for a more uniform look regardless of the developer's and the user’s PCs.

Using the code

In order to disable Windows themes, you actually need to reference a Windows API DLL uxtheme.dll and set the theme to nothing. I could not find an easier way to do this. There does not seem to by any property exposed on the application or form level that allows you to disable themes.

In order to make this process easier and to avoid pasting the same code in all of the forms in my application, I created a base form that contains the necessary code.

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace DisableWindowsThemesExample
    public class BaseForm : Form
        [DllImport("uxtheme", ExactSpelling = true, CharSet = CharSet.Unicode)]
        public extern static Int32 SetWindowTheme (IntPtr hWnd, 
                      String textSubAppName, String textSubIdList);

        public BaseForm()
            SetWindowTheme(Handle, "", "");

Then, you simply inherit your form from the base form, and call the base constructor. (The call to the base constructor is actually not necessary since it is implicit.)

public partial class ExampleForm : BaseForm
    public ExampleForm(): base()

Furthermore, in order to disable themes for your controls, you have to set the FlatSyle of the control to System and call SetWindowTheme for that control.

rdoNonThemed.FlatStyle = FlatStyle.System; 
grpNonThemed.FlatStyle = FlatStyle.System;
btnNonThemed.FlatStyle = FlatStyle.System;
SetWindowTheme(grpNonThemed.Handle, "", "");
SetWindowTheme(rdoNonThemed.Handle, "", "");
SetWindowTheme(btnNonThemed.Handle, "", ""); 

Download the solution above to see a working example.


  • 2008-May-28 - Initial version, fixed download link.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...


Comments and Discussions

GeneralRule of Thumb Pin
The_Mega_ZZTer29-May-08 19:21
memberThe_Mega_ZZTer29-May-08 19:21 
QuestionRe: Rule of Thumb Pin
Adam Berent30-May-08 4:28
memberAdam Berent30-May-08 4:28 
I am not sure I understand your Rule of Thumb post exactly. I am not discussing using System Colors such as Color.Control and complaining that this Color.Control color looks different in Vista. I am also not discussing how certain foreground colors look in comparison with other colors.

What I am saying is:

1. Lets say I have a list box with a white background (Color.White)
2. Lets say I specify a foreground color to: 243, 242, 231

With Themes enabled:

1. Under XP this foreground color looks like light silver.
2. Under Vista the foreground color disappears it becomes white on white (not readable)

Now remember I specified an RGB color for both the foreground and background so I would expect that it would render the same on both PCs. But it does not.

The only way I can see to disable this behavior is to disable themes in my application. I don’t see how this third party tool or the link on how not to mix colors will help me. Maybe you can clarify?

GeneralFixed Download Link. Pin
Adam Berent29-May-08 8:38
memberAdam Berent29-May-08 8:38 
GeneralDownload link broken Pin
leppie29-May-08 8:27
member leppie 29-May-08 8:27 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 17 Jul 2008
Article Copyright 2008 by Adam Berent
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid