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 Pin
    RancidCrabtree
    9:17 10 Mar '07  
    GeneralHow enable XP style form Contextmenu? Pin
    Ehsan Golkar
    8:42 14 Sep '05  
    Generalgreat resource for doing this Pin
    scottfm
    6:57 29 Nov '04  
    Generalbutton.ForeColor doesn't work Pin
    Cong Dan Luong
    17:59 8 Oct '04  
    GeneralRe: button.ForeColor doesn't work Pin
    Barretto VN
    23:31 10 Oct '04  
    GeneralRe: button.ForeColor doesn't work Pin
    Cong Dan Luong
    17:07 11 Oct '04  
    QuestionRe: button.ForeColor doesn't work Pin
    shobha0202
    19:29 9 Mar '09  
    Generalthis style in visual C++ 6.0 Pin
    Anonymous
    16:43 7 Jun '04  
    GeneralRe: this style in visual C++ 6.0 Pin
    Barretto VN
    23:58 15 Jun '04  
    GeneralDataGrid still not working Pin
    SchmidtND
    21:45 24 May '04  
    GeneralRe: DataGrid still not working Pin
    Barretto VN
    4:19 25 May '04  
    GeneralRe: DataGrid still not working Pin
    SchmidtND
    13:22 6 Oct '04  
    GeneralHow to get XP style property page background. Pin
    Joel Matthias
    13:09 1 Nov '03  
    GeneralRe: How to get XP style property page background. Pin
    Heath Stewart
    11:48 2 Nov '03  
    GeneralWindows 2003 Server Pin
    mogwai
    11:40 1 Nov '03  
    GeneralRe: Windows 2003 Server Pin
    mogwai
    11:45 1 Nov '03  
    GeneralAlready Posted Pin
    Heath Stewart
    6:32 1 Nov '03  
    GeneralRe: Already Posted Pin
    Barretto VN
    21:30 1 Nov '03  
    GeneralRe: Already Posted Pin
    Heath Stewart
    11:52 2 Nov '03  
    GeneralRe: Already Posted Pin
    Derek Lakin
    22:16 2 Nov '03  
    GeneralRe: Already Posted Pin
    Heath Stewart
    3:40 3 Nov '03  
    GeneralRe: Already Posted Pin
    Allan Wissing
    0:10 6 Nov '03  
    GeneralRe: Already Posted Pin
    Daniël Pelsmaeker
    6:32 18 Nov '03  
    GeneralApplication.EnableVisualStyles is't OK Pin
    Juan211
    4:47 1 Nov '03  
    GeneralRe: Application.EnableVisualStyles is't OK Pin
    Mighell01
    7:48 1 Nov '03  


    Last Updated 31 Oct 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009