Click here to Skip to main content
12,948,105 members (71,327 online)
Click here to Skip to main content
Add your own
alternative version


33 bookmarked
Posted 6 Jun 2004

WinXpStyle Class

, 6 Jun 2004
Rate this:
Please Sign up or sign in to vote.
You can use this class for Windows XP Style Forms.

Without WinXpStyle Class

With WinXpStyle Class


.NET Framework documentations [1] arguments about how to implement Windows XP visual style, therefore, according to all documentation I have put all in a simple standalone class called WinXpStyle, for example with it you haven't got to think about the manifest [1] file because WinXpStyle class builds it for you if you want (it is not necessary) and also sets FlatStyle property to System for each object like Button, RadioButton, GroupBox and CheckBox controls.

This class is very easy to use, just add to your project, check the namespace name, and invoke the class according to explanations given below.

Using the class WinXpStyle without manifest

WinXpStyle class is a stand alone class, and all its member are static, so creating an instance is not necessary. There are only two steps to use WinXpStyle class, be sure that it is in the same namespace as the form class, so:

1) You have to write in the Main function of the form class the following:

static void Main() 
  Application.Run(new Form1());

Where Application.EnableVisualStyles() method enables Windows XP visual styles for the application. Controls will draw with visual styles if the control and the operating system supports it. To have an effect, EnableVisualStyles must be called before creating any controls in the application; typically, EnableVisualStyles is the first line in the Main function. A separate manifest is not required to enable visual styles when calling EnableVisualStyles.

2) You have to call FormLoad function of the WinXpStyle class inside Form_load event of Form class as you see below

private void Form1_Load(object sender, System.EventArgs e)

The FormLoad function sets FlatStyle property to System for each object that derives from ButtonBase likes Button, RadioButton, GroupBox and CheckBox controls. It is necessary to show the objects using visual style.

Using the class WinXpStyle with manifest file

If you want to use manifest file [1] you need in this case two steps, because it is not necessary to call Application.EnableVisualStyle in Main function. So you have to do the following things:

1) You have to create manifest file using Manifest function of WinXpStyle class in your Form Class constructor. In this case we assume that "FormTest2" is the name of our project and also is an assembly name.

public Form1()

Where "FormTest2" is an Assembly Name: it's a name of the output file will hold assembly metadata (manifest). The function Manifest of this class makes manifest file in the correct directory.

2) You have to call FormLoad function of the WinXpStyle class inside Form_load event of Form class as you see below

private void Form1_Load(object sender, System.EventArgs e)

The WinXpStyle class

I consider that is it a stand alone class and also all its public function are static. Also you can see in the picture below the association between Form class and WinXpStyle Class


using System;
using System.Windows.Forms;
using System.IO;

namespace WinXpStyle
   /// <SUMMARY>
   /// Summary description for WinXpStyle by Hugo C Romano.
   /// Using Windows XP Visual Styles With Controls on Windows Forms
   /// Based on Visual Studio .NET Technical Articles
   /// </SUMMARY>
   public sealed class WinXpStyle
      private static string fileName;
      private static string executableName;
      // You need to see if Windows XP is running and 
      // whether the manifest file is present, 
     // if it not exist constructor create it.

      private  WinXpStyle() {}

      public static void Manifest(string ExeFile) 
         executableName = ExeFile ;
         fileName = executableName + ".exe.manifest";
            Application.ExecutablePath + ".manifest"))

      // Create manifest XML file
      private static void CreateManifest() 
         StreamWriter outStream = File.AppendText(fileName);
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
       "<ASSEMBLY ?manifestVersion='\"1.0\"' + ? "+
       "<ASSEMBLYIDENTITY + ? type='\"win32\"/' "+
   "outStream.WriteLine(? outStream.WriteLine(?name='\"Microsoft." "+
   "+executableName+"." +   executableName+"\"");' ?"+
   " version='\"\"'>");
     "<DESCRIPTION>.NET control deployment tool</DESCRIPTION>");
        "<ASSEMBLYIDENTITY language="'\""*\"/' + "+
   "? type='\"win32\"' ?processorArchitecture="+
   "'\"X86\"' version='\"\"' ?publicKeyToken"+
   "='\"6595b64144ccf1df\"' ?Windows.Common-Controls"+
   "\? name='\"Microsoft."'>");
         catch(System.Exception e) 

      // This code controls if FlatStyle property is FlatStyle.System.
      private static void RecursivelyFormatForWinXP(Control control)
         for(int x = 0; x < control.Controls.Count; x++)
            // If the control derives from ButtonBase, 
            //  set its FlatStyle property to FlatStyle.System.
            if(control.Controls[x].GetType().BaseType == typeof(ButtonBase))
               ((ButtonBase)control.Controls[x]).FlatStyle = 
            // If the control holds other controls, 
            // iterate through them also.
            if(control.Controls.Count > 0)

      // You need to see if Windows XP is running and 
      // whether the manifest file is present.

      public static void FormLoad(object sender, 
           System.EventArgs e, Form thisForm)
         // Makes sure Windows XP is running  
         if(Environment.OSVersion.Version.Major > 4 
            & Environment.OSVersion.Version.Minor > 0 )
            // Iterate through the controls.
            for(int x = 0; x < thisForm.Controls.Count; x++)
               // If the control derives from ButtonBase,
               // set its FlatStyle property to FlatStyle.System.
               if(thisForm.Controls[x].GetType().BaseType == 
                  ((ButtonBase)thisForm.Controls[x]).FlatStyle = 


  • [1] Seth Grossman, Visual Studio Team, Microsoft Corporation, January 2002
  • [2] .NET framework class library, Enable Windows XP visual styles for the application


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Israel Israel
Information Systems Engineer-National Technological University–Argentina-1995
Systems Analyst-National Technological University–Argentina-1991

Spanish (mother tongue),English,Hebrew

•Programmer of:C#,C++,C,JAVA,Progress 4GL, VB,VFPro,Access
•Data Bases Management in SQL Server, Progress ,Interbase and MySQL
•Operative System Windows XP, Windows NT 4.0, Windows 2000, Windows 3.11
•Networks: Windows, Novell, TCP/IP
•Knowledge: .Net Framework, MFC, COM,DDE, HTML, DHTML,XML,ADO,ODBC, Java scrip and VB script

•Designing, developing and supporting software for many commercial companies : Accounting – Billing – stock control – costumer control – salesperson – from 1995 to 2002.
•Consultant of telecomunication network, Municipality of Yerba Buena – Tucuman – Argentina, 1997 - 1998
•Consultant and Supervisor of informatic project , Govermment of Tucuman, Cience and Tehnology Department 1996 – 1998
•STARTEL S.A. Official Agent in telecommunications : Designed telecommunication project, using VSAT Technology and WAN network. from 1995 to 1998
•TECOTEX S.A. textile factory. Responsible for all development projects for the technical, cost, schedule, and testing, from 1991 to 1995:
Control of knitting plant production, spinning plant production, textile plant preparation, spinning plant preparation, mix fiber plant,preparation, Stock

System Department (National Technological University,FRT–1995 to 2002), responsible for:
System Design (UML), System Design Methodology (Unified Process Meotodology), System Design Subject, Data Base Systems, Data Management, Paradigms of Programming, Programming (Pascal), Data System

At National Technological University, Regional Tucuman Department
Research made on “Access to Educational Resources through 2nd and 3rd generational mobile phones using UMTS technology”.

You may also be interested in...

Comments and Discussions

GeneralThanks you saved my day ! Pin
mee2011-Jun-07 21:57
membermee2011-Jun-07 21:57 
GeneralI use Win 2000, I can't demo this version. Pin
nghiak46cb31-Jul-05 23:37
membernghiak46cb31-Jul-05 23:37 
GeneralRe: I use Win 2000, I can't demo this version. Pin
MyDreamer22-Nov-05 3:54
memberMyDreamer22-Nov-05 3:54 
Generalbutton.ForeColor doesn't work Pin
Cong Dan Luong8-Oct-04 16:56
memberCong Dan Luong8-Oct-04 16:56 
GeneralEnableVisualStyles Pin
Tom Spink8-Jun-04 1:37
memberTom Spink8-Jun-04 1:37 
GeneralRe: EnableVisualStyles Pin
dzCepheus10-Jun-04 16:58
memberdzCepheus10-Jun-04 16:58 
GeneralRe: EnableVisualStyles Pin
Tom Spink10-Jun-04 21:26
memberTom Spink10-Jun-04 21:26 
GeneralRe: EnableVisualStyles Pin
dzCepheus11-Jun-04 1:50
memberdzCepheus11-Jun-04 1:50 
GeneralRe: EnableVisualStyles Pin
HugoRomano17-Jun-04 4:18
memberHugoRomano17-Jun-04 4:18 

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
Web02 | 2.8.170524.1 | Last Updated 7 Jun 2004
Article Copyright 2004 by HugoRomano
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid