WinXP theming in your Winforms apps

I’m about to embark an adventure called Developing a .NET Windows Forms application with a collegue of mine. Untill now, I only embarked web applications, so this is a new one.

My collegue included a class he found on CodeProject, to handle WinXP theme support very easily. With every form load, you just add the following code and it supports WinXP themes. When activated ofcourse, which I never do! But the support in our application is nice nevertheless.

You can find the class here.

private void MainForm_Load(object sender, System.EventArgs e)
    WinXpStyle.FormLoad(sender, e, this);

Now playing: Jessica SimpsonSweetest Skin

You may also like...

5 Responses

  1. Ernst says:

    "Untill now, I only embarked web applications, so this is a new one."

    You do not embark, you embark ON…

    I’m about to embark on …

    Untill >> Until

    Excellent choice to use english on this blog 😉

  2. Ernst says:

    Just nagging, Dennis 😉

  3. Sorry Ernst, I was in a hurry writing this. You were waiting outside to got the the "appie" 🙂

  4. Ernst says:

    OK, now for something serious…

    I’ve looked at the class…

    Here’s what happens with the FormLoad method: before initializing any of the visual components, the class checks all of the components and its children and if its derived from buttonbase it sets the FlatStyle property.

    If you put a manifest file in the directory of a winform app, it automatically tells the application that it can use the new version of the windows common controls, if there are any (it doesn’t work on W2K because the DLL is not there).

    So what the Manifest method does it put it in place automatically for you.

    My preference would be to use the Manifest method because this tells the application to use the new controls, instead of modifying every control when starting the app.

    Beter yet, make your own manifest file and place it in the app folder, so that if a newer version of the manifest file (i.e. newer controls) can be used, it isn’t replaced by this class.

    So, don’t use it, make your own manifest file, it’s easy!

  5. Ernst says:

    OK, wait a minute…

    If you can use Application.EnableVisualStyles(), why bother with the manifest?

    I stumbled across this URL:

    What is says: in V1.0 you needed the manifest for XP looks, in V1.1 you can use Application.EnableVisualStyles.

    So why does this class bother with the manifest file? The article already mentions the EnableVisualStyles method…?

    Even worse… if I understand correctly, the Manifest method won’t work if the FlatStyle.System isn’t set on the buttons…

    So… use Application.EnableVisualStyles() and all is well.

    All is well? Not exactly…

    Read this:

    For those controls that have FlatStyle properties, in all modes except FlatStyle.System, Windows Forms custom-renders the controls. In v1.0 and v1.1, the Windows Forms rendering code is not "theme-aware", so EnableVisualStyles has no effect unless comctl32 itself does the rendering. The FlatStyle.System setting does exactly that – tells Windows Forms to allow comctl32 to render the control. Unfortunately, in this mode, cool features like setting the BackColor or assigning an image to the control do not work, since to support these, Windows Forms needs to do the rendering.

    So, standard buttons in XP style are working fine, but using Application.EnableVisualStyles() disabled your own buttons with images etc.

Leave a Reply

Your email address will not be published. Required fields are marked *