Click here to Skip to main content
Email Password   helpLost your password?
  • Download demo project - 9 Kb

    Sample Image - XPStyleUI.jpg

    Introduction

    This article shows the technique of giving your C# Applications a Windows XP-like appearance.

    Background

    Recently when I developed my first C++ application using Visual Studio .NET I found that the TreeView and ListView controls looked somewhat similar to those found on Windows XP, the block for + and - had a 3d look and when I move the cursor on the column-headers of ListView a yellow border appears; since such a facility is not available in C# I decided to probe the C++ project to see if such a UI could be provided in C# and found the right information which allows to give C# applications XP Style look to controls, the method of doing so surprisingly turned out to be quite simple.

    Version

    This works in .NET 7.0 and 7.1 and Windows XP Operating System (not Windows 2000 or Windows 2003 Server); in Visual Studio .NET 7.1 the application object has a property Application.EnableVisualStyles().

    How To

    Using Visual Studio .NET wizard create a "Windows Application" , on the displayed form drop the following controls

    Now Build Solution and Start your application, you will see no effect on the displayed window. Now open NotePad and mark and copy the code in the "Contents of Manifest file" section below the block within the border only and paste in the newly opened NotePad file and save the file with name "your_project_name".exe.manifest in "your_project"\bin\debug folder OR download the Demo zip and copy the included "WindowsApplication1.exe.manifest" file in the the above mentioned folder and rename it; now Start your project (no need to rebuild solution), you will still find no effect on the displayed Window, read the section "Setting Properties" to know more.

    You have to do a copy/pase operation since only select type of files can be posted in the article.

    Point to Note

    You can drop / copy the above Manifest file "WindowsApplication1.Exe.manifest" in the same location as your completed applications executable and rename the file to the "name of your application".Exe.manifest (without quotes) and remember to distribute this file along with the executable.

    Setting Properties

    Some of the controls in Visual Studion .NET have a property named FlatStyle, this property is set to "Standard" for these controls by default, you have to set this property to System for these controls to have a Windows XP Style look ("System" means that the Operating system is responsible setting for its Visual Style). below is a Table showing names of controls which have such property.


    Control FlatStyle
    Label Yes
    LinkLabel Yes
    Button Yes
    TextBox No
    MainMenu No
    CheckBox Yes
    RadioButton Yes
    BroupBox Yes
    PictureBox No
    Panel No
    DataGrid No
    ListBox No
    CheckedListBox No
    ComboBox No
    ListView No
    TreeView No
    TabControl No
    MonthCalendar No
    DateTimePicker No
    HScrollBar No
    VScrollBar No
    Splitter No
    DomainUpDown No
    NumericUpDown No
    TrackBar No
    ProgressBar No
    RichTextBox No

    Drawback of FlatStyle

    Setting Flatstyle to "System" prevents these controls from displaying Images, this possibly is the reason why this property has been added to these controls, if you intend to display images in any of these controls then you must set it to anything other then "System".

    Contents of Manifest file

    Below is the content of the Manifest file "WindowsApplications1.Exe.manifest", this file is in xml format and can be opened and edited using any text editor like notepad or wordpad, and you can add the name of your project in this file but it will not have any effect on the application

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity 
        version="1.0.0.0" 
        processorArchitecture="X86" 
        name="Microsoft.Windows.SysInfo"
        type="win32" 
    />
    <description>Your app description here</description>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity 
                type="win32" 
                name="Microsoft.Windows.Common-Controls" 
                version="6.0.0.0" 
                processorArchitecture="X86" 
                publicKeyToken="6595b64144ccf1df" 
                language="*" 
            />
        </dependentAssembly>
    </dependency>
    </assembly>
    
    

    Note

    This method of giving your applications a XP Style look does not embed the information in the manifest file in the completed applications, if the apps you develop are for in-house purposes or to clients you know personally this is the best approach, but if you are developing applications for unknown client's you can lookup the .NET utilities Application Linker (al.exe) and Strong Name (sn.exe) to embed information about your product in the applications executable, these utilities are generally run in a Dos-Console and have many switches to be set.

    History

  • You must Sign In to use this message board.
     
     
    Per page   
     FirstPrevNext
    GeneralImporting manifest as a resource
    RancidCrabtree
    9:17 10 Mar '07  
    In VC++ 6.0, it was trivially simple to import the manifest as a resource.

    Is there a way to do this with Visual Studio 2003 and C#?
    GeneralHow enable XP style form Contextmenu?
    Ehsan Golkar
    8:42 14 Sep '05  
    Thank's,good text.but i have probelm in contextmenu.When you click right in windows in "OpenWith" item you sea item both icon and this icon have XP Style !!!.when i add this icon in ListView whit your text of XP style i saw better icon whit best resulotion but in Contextmenu i could NOT !!!
    if you want i could send my program.Please help me
    thanks a lot.
    Generalgreat resource for doing this
    scottfm
    6:57 29 Nov '04  
    Thanks for the article. I've been trying to figure this one out.

    Here's another source I found:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchUsingWindowsXPVisualStylesWithControlsOnWindowsForms.asp
    [^]
    Generalbutton.ForeColor doesn't work
    Cong Dan Luong
    17:59 8 Oct '04  
    hi!
    [design]
    //
    // button
    //
    this.button.ForeColor = System.Drawing.Color.Red;

    [void Main()]
    static void Main()
    {
    Application.EnableVisualStyles(); Application.Run(new Calculator());
    }

    [form load event]
    private void Form_Load(object sender, System.EventArgs e)
    {
    WinXpStyle.FormLoad(sender, e, this);
    }

    but, when application run, button.ForeColor doesn't work.
    It's black not red
    GeneralRe: button.ForeColor doesn't work
    Barretto VN
    23:31 10 Oct '04  
    i suppose, you cannot have flatStyle == "System" and then set the ForeColor or BackColor, because the painting of the button is done by the button's paint method.
    if you want to color the button to your liking, then you must create a sub-class of Button and in the sub-class have a paint method in which you paint the button as you like, not very easy though. and ofcourse your button will not look a XP-Style button

    GeneralRe: button.ForeColor doesn't work
    Cong Dan Luong
    17:07 11 Oct '04  
    So, how can I have the button look like a XP-Style & customize ForeColor? Confused
    Please look at Calculator application in XP OS, which have some ForeColor = RED & some ForeColor = BLUE
    QuestionRe: button.ForeColor doesn't work
    shobha0202
    19:29 9 Mar '09  
    am facing problem when tried to change forecolor for a disabled button..have set flatstyle = Standard..

    pls any one know the solution..
    Generalthis style in visual C++ 6.0
    Anonymous
    16:43 7 Jun '04  
    this style of buttons works in visual C++ 6.0?
    GeneralRe: this style in visual C++ 6.0
    Barretto VN
    23:58 15 Jun '04  
    In Visual Studio .Net this is by default in C++.

    GeneralDataGrid still not working
    SchmidtND
    21:45 24 May '04  
    Hi

    Following your instructions to the letter, I am still unable to get the datagrid to render in the preferred xp style. My grid's border is the old style 3d bevel, and grid columns have no orange underscoring. I am using Framework version 1.1. I am not using a strongly named assembly, i have simply copied and renamed the manifest file.

    Regards

    Nick
    GeneralRe: DataGrid still not working
    Barretto VN
    4:19 25 May '04  
    This style of Orange underscore i suppose is applicable to ListView i am not sure about DataGrid

    GeneralRe: DataGrid still not working
    SchmidtND
    13:22 6 Oct '04  
    Thank-you. I wonder if anyone has re-styled the datagrid, it looks pretty funny on my xp forms with the old 3d border and no gradient fill... Maybe microsoft will release another version...
    GeneralHow to get XP style property page background.
    Joel Matthias
    13:09 1 Nov '03  
    When XP styles are enabled the property page tabs look correct but the pages themselves do not have the correct background. Does anybody know how to fix this?

    Thanks - Joel

    VssConnect - Remote SourceSafe(r) Access http://www.voxcode.com[^]
    GeneralRe: How to get XP style property page background.
    Heath Stewart
    11:48 2 Nov '03  
    You'll have to P/Invoke various functions from the Theme API (see MSDN for docs on the Theme API) and call a couple functions (like OpenTheme, for one) to paint the background yourself.

     
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
    -----END GEEK CODE BLOCK-----
    GeneralWindows 2003 Server
    mogwai
    11:40 1 Nov '03  
    This method does work on Windows 2003 - if you have the themes service switched on...
    GeneralRe: Windows 2003 Server
    mogwai
    11:45 1 Nov '03  
    In fact this method won't work at all if your users have the themes service switched off on Windows XP. If you are developing a UI that is dependent on having a 'nice' looking interface, then you'd be better off at looking at some of the XP style controls on CP. We use Vol 3 of the Infragistics NetAdvantage suite, which has a full set of XP themed controls for use on all platforms capable of running the .NET framework.
    GeneralAlready Posted
    Heath Stewart
    6:32 1 Nov '03  
    Next time you post, make sure to not post duplicate articles. I already did this a long time ago: http://www.codeproject.com/csharp/dotnetvisualstyles.asp[^]

     
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
    -----END GEEK CODE BLOCK-----
    GeneralRe: Already Posted
    Barretto VN
    21:30 1 Nov '03  

    Heath Stewart wrote: Next time you post, make sure to not post duplicate articles. I already did this a long time ago...

    Is it a must that i have to read each and every article on CP before posting one of my own , i don't do that, i have not even viewed 5% of the articles available in the C# programming section , leave alone the rest of them in other sections (remember i am a C++ Developer).
    Other then the Manifest file there is nothing common between yor article and mine, your article talks of some Keyfile, Comctrl32.dll (with specific version no.) and it uses StrongName Utility about which i have casually mentioned at the end, who has the patience for details like ComCtrl32.dll Sn.exe, when all this can be achieved, as i have shown, by a simple copy and rename command, your article may be exhaustive but mine does it in a very simle manner without being too technical.
    Using the Console based utilities takes a little bit of getting accustoimed, it is not as simple as you might have everyone believe, there is need to set up environment variables.


    GeneralRe: Already Posted
    Heath Stewart
    11:52 2 Nov '03  
    They are alike. I mention which controls support themes, setting the FlatStyle, and the .NET 1.1 change Application.EnableVisualStyles is mentioned in the article-based forum. I go even further to explain how to enable visual styles without using a separate manifest file even when you sign your code (and any good library or application should). That's what the command-line programs are for.

    And, yes, you are supposed to check CP to see if an article already exists on the subject on which you want to post. You can add something to it in your own article or take a completely different angle.

     
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
    -----END GEEK CODE BLOCK-----
    GeneralRe: Already Posted
    Derek Lakin
    22:16 2 Nov '03  
    As a CP Editor you of all people should know that CodeProject is home to many articles that cover the same subject. This doesn't make any one of those articles less useful or less relevant.

    Let's show a bit more tolerance and support around here. Rose


    Derek Lakin

    Providing instant integrated access to an online repository of .NET components from Visual Studio.NET and #Develop.
    Personal musings on life, the universe and everything as well as commentary on my software & digital graphics life.

    GeneralRe: Already Posted
    Heath Stewart
    3:40 3 Nov '03  
    As a CP editor, I can assure you were are discussing ways to avoid duplicate articles. Yes, some articles take different approaches or present new ideas and that's good. Some don't.

     
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
    -----END GEEK CODE BLOCK-----
    GeneralRe: Already Posted
    Allan Wissing
    0:10 6 Nov '03  
    When learning something new, there is certainly an advantage if there are duplicate articles on a subject. Especially when the approach is different, as the two article to date on this subject are. I commend you both on presenting interesting and beneficial articles.
    GeneralRe: Already Posted
    Daniël Pelsmaeker
    6:32 18 Nov '03  
    I agree. Another advantage is that both Baretto VN and you learned a lot from writing the article.

    And when you are going to reject his article only because you where first, then I'd say that you seriously revise your opinion about this article.
    If he would be the first, you wouldn't like it either when you wrote a nice and good article, and he says that he doesn't like your article (or maybe not even want to edit it, if he'd be an editor), just because he was first! Tolerance. Rose

    Albert Einstein and Marilyn Monroe were seated together at a table.
    "Hey Albert," said Marilyn. "Imagine if we had a baby and it had my looks and your brains-it could do anything it wanted."
    "Yes, my dear," replied Einstein. "But what if it has my looks and your brains?"

    GeneralApplication.EnableVisualStyles is't OK
    Juan211
    4:47 1 Nov '03  
    [STAThread]
    static void Main( )
    {
    Application.EnableVisualStyles( );
    Application.DoEvents( );
    Application.Run( new MyForm );
    }

    Wink

    Juan Carlos Guzman
    Venezuela
    GeneralRe: Application.EnableVisualStyles is't OK
    Mighell01
    7:48 1 Nov '03  
    But only for the 1.1 version of the framework Roll eyes


    Last Updated 1 Nov 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010