Click here to Skip to main content
11,922,641 members (57,122 online)
Click here to Skip to main content
Add your own
alternative version


92 bookmarked

StylesSheetManager - A 'CSS like component' for WinForms

, 25 Oct 2006
Rate this:
Please Sign up or sign in to vote.
StylesSheetManager is a 'CSS like component' for Windows Forms applications.

Sample Image

Sample Image


When you create an ASP.NET application, you can use a CSS file to style your graphic controls, using the CssClass property. But actually, there is no such solution for WinForms applications. Now, there is one: the StylesSheetManager.

Using the component

To use the StylesSheetManager, you only have to do the following:

  1. Create a styles sheet file (an XML file). The XML file containing the styles should be defined like the following:
    <?xml version="1.0" encoding="utf-8" ?>
    <StylesSheetFile xmlns:xsi="" 
            <Style Name="FormType1">
                    <Property Name="BackColor" Value="White" />
                    <Property Name="Text" Value="Personal information" />
                    <Property Name="Enabled" Value="true" />
            <Style Name="DataGridType1">
                    <Property Name="RowsDefaultCellStyle.BackColor" 
                              Value="White" />
                    <Property Name="AlternatingRowsDefaultCellStyle.BackColor" 
                              Value="214,222,247" />
                    <Property Name="Columns[0].HeaderText" 
                              Value="Color name" />
                    <Property Name="Columns[1].HeaderText" Value="My rate" />
            <Style Name="TabControlType1">
                    <Property Name="Enabled" Value="true" />
                    <Property Name="TabPages[0].BackColor" Value="White" />
                    <Property Name="TabPages[1].BackColor" Value="White" />
                    <Property Name="TabPages[2].BackColor" Value="White" />
            <Style Name="LabelType1">
                    <Property Name="TextAlign" Value="TopLeft" />
                    <Property Name="BorderStyle" Value="None" />
                    <Property Name="ForeColor" Value="72,94,158" />
                    <Property Name="Font" 
                              Value="Microsoft Sans Serif,8.25pt,style=Regular" />
                    <Property Name="Height" Value="20" />
                    <Property Name="Enabled" Value="true" />
            <Style Name="LabelType2">
                    <Property Name="ForeColor" Value="Red" />
                    <Property Name="Font" 
                              Value="Microsoft Sans Serif,8.25pt,style=Bold" />
            <Style Name="TextBoxType1">
                    <Property Name="TextAlign" Value="Left" />
                    <Property Name="BorderStyle" Value="Fixed3D" />
                    <Property Name="Font" Value="Tahoma,10,style=Regular" />
                    <Property Name="Height" Value="20" />
                    <Property Name="Width" Value="200" />
                    <Property Name="BackColor" Value="214, 222, 247" />
            <Style Name="HyperLinkType1">
                    <Property Name="BorderStyle" Value="None" />
                    <Property Name="ForeColor" Value="Blue" />
                    <Property Name="Font" 
                              Value="Tahoma,10,style=Italic,Underline" />
                    <Property Name="Height" Value="30" />
                    <Property Name="Width" Value="200" />
                    <Property Name="Enabled" Value="true" />
            <Style Name="ButtonType1">
                    <Property Name="TextAlign" Value="TopLeft" />
                    <Property Name="ForeColor" Value="Black" />
                    <Property Name="BackColor" Value="214;222;247" />
                    <Property Name="Font" Value="Tahoma,8.25,style=Italic" />
                    <Property Name="Height" Value="23" />
                    <Property Name="Enabled" Value="true" />
            <Style Name="ComboBoxType1">
                    <Property Name="BackColor" Value="White" />
                    <Property Name="Font" Value="Tahoma,10,style=Italic" />
                    <Property Name="Height" Value="30" />
                    <Property Name="Width" Value="200" />
                    <Property Name="Enabled" Value="true" />
            <Style Name="RadioButtonType1">
                    <Property Name="ForeColor" Value="Blue" />
                    <Property Name="Font" Value="Verdana,8,style=Regular" />
                    <Property Name="Width" Value="150" />
                    <Property Name="Enabled" Value="true" />

    As you can see, a style is defined by a name and properties. The property tag corresponds to a property of the control you want to style. It is defined by a name (e.g.: BackColor) and a value (e.g.: 255;124;157). Because the StylesSheetManager component uses TypeConverter, internally, to convert a value stored in an XML file to an object, you must respect the TypeConverter format (e.g.: value="Microsoft Sans Serif;8,25pt;style=Bold, Italic"). See the MSDN site for more explanations.

  2. Drop a StylesSheetManager component on your form.

  3. Select the style sheet file you want to use. To do it, just add a StylesSheetFilename key to the appSettings section of the app.config file, like the following:

  4. Last but not least, set the Style property of the controls of your form (not all, just the ones you want to style) to a value which is present in the style sheet file.

  5. Now, just launch your application.

Points of interests

  • IExtenderProvider: this component is based on the IExtenderProvider interface which permits to add properties to controls at design time (see the StylesSheetManager.cs file).
  • Serialization: The XmlSerializer.Deserialize()method is used to read the styles sheet file (see the StylesSheetFileManager.cs file) which permits us to easily do the inverse operation: save the styles in XML.
  • Reflection/TypeDescriptor: To get/set value to a property of a control, Reflection is used. To convert a string stored in an XML file to the right type of property, TypeDescriptor is used (see the PropertySetter.cs file).
  • Exception management / Localization: all exceptions thrown by this component are grouped in the StylesSheetException class. The messages corresponding to these exceptions are stored in a resource file, and is available in English.
  • EnvDTE namespace (Environment Design Time): Displaying the new appearance of controls at design-time is a little more complicated than at execution time. Indeed, when you click on a form to open it in the designer, the executing application is devenv.exe, and so the configuration is devenv.exe.config, and not the one of the current project. Because I need app.config to store the StylesSheetFilename, I had to use the EnvDTE namespace (see GetAppConfigPath() in the StylesSheetManager.cs file) to retrieve the good configuration file.


  • 2006/10/14
    • Make the read of the styles sheet file independent of the regional settings of the operating system. To do it, I force the thread to English culture => The format of the file has changed. Now, the list separator is "," and the decimal separator is ".". To be able to continue to use your old version styles sheet file, do the following: replace all "," by ".", then all ";" by ",". For composed style font ("Tahoma,8.25,style=Italic,Underline"), make sure there is a "," between styles (Italic,Underline) and not a "."
  • 2006/09/24
    • a new Form (ChildForm3_Dynamic) has been added to the demo to demonstrate the use of the StylesSheetManager component with dynamic control creation. improved error messages, and now all messages are in English (instead of French).
  • 2006/07/30
    • the appearance of the controls is visible in the designer (style is set when opening a form in the designer): thanks to "Emanuele" (post).
    • the style sheet file name is stored in app.config, and becomes the same for all forms => performance increase (file is read only once): thanks to "Yancyn" (post).
  • 2006/07/19
    • the indexed properties are managed: thanks to "Matt" (post).
  • 2006/07/14
    • first version.


I hope you will enjoy this component. I really want to thank "Atlas2002" who wrote the first message on this article and encouraged me to continue.


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
France France
Software developer for Capgemini company.

You may also be interested in...

Comments and Discussions

QuestionWhere can i find the stylesheetmanager.dll in the solution Pin
Ahad Saddam Hussain10-Sep-15 23:22
memberAhad Saddam Hussain10-Sep-15 23:22 
QuestionError Pin
Member 1186688928-Jul-15 1:45
memberMember 1186688928-Jul-15 1:45 
Questioncss is not implement on my from Pin
Member 1143514915-Jun-15 2:08
memberMember 1143514915-Jun-15 2:08 
Questionhow to add styles Sheet manager in .frame work 3.5 visual studio 2010 Pin
Member 1099477131-Aug-14 21:46
memberMember 1099477131-Aug-14 21:46 
QuestionSir, My form is not showing any changes please help Pin
Member 1104198827-Aug-14 22:22
memberMember 1104198827-Aug-14 22:22 
Questionwhile editing stylesheets, changes not updating in forms Pin
Prasannah16014-Sep-12 1:48
memberPrasannah16014-Sep-12 1:48 
AnswerRe: while editing stylesheets, changes not updating in forms Pin
mon_compte_anti_spam13-Nov-12 7:01
membermon_compte_anti_spam13-Nov-12 7:01 
QuestionRe: while editing stylesheets, changes not updating in forms Pin
Member 1143514914-Jun-15 23:25
memberMember 1143514914-Jun-15 23:25 
Questionhow can i add my own new style in this manager? [modified] Pin
khushbujasmine20-Sep-11 21:19
memberkhushbujasmine20-Sep-11 21:19 
QuestionStylesSheetFilename error [modified] Pin
Member 802085828-Jul-11 1:20
memberMember 802085828-Jul-11 1:20 
AnswerRe: StylesSheetFilename error [modified] Pin
afcm66622-Aug-12 14:00
memberafcm66622-Aug-12 14:00 
GeneralI doesn't maintain this component anymore Pin
mon_compte_anti_spam10-Jun-11 12:06
membermon_compte_anti_spam10-Jun-11 12:06 
QuestionIs StylesSheetManager.dll Free? Pin
ajaypediredla2-Feb-11 22:54
memberajaypediredla2-Feb-11 22:54 
AnswerRe: Is StylesSheetManager.dll Free? Pin
mon_compte_anti_spam10-Jun-11 12:05
membermon_compte_anti_spam10-Jun-11 12:05 
AnswerRe: Is StylesSheetManager.dll Free? Pin
AnjaniRahul2-May-12 1:34
memberAnjaniRahul2-May-12 1:34 
QuestionI am facing name space issue in stylessheetmanager Pin
ramachandransathish20-May-10 1:20
memberramachandransathish20-May-10 1:20 
QuestionHow to set background image ? Pin
Member 45575835-Jan-10 22:35
memberMember 45575835-Jan-10 22:35 
QuestionDoes not work on Windows Mobile form applications? Pin
xanoumissa10-Dec-09 3:34
memberxanoumissa10-Dec-09 3:34 
GeneralIt's work better with Regional Settings accordingly Pin
BDisp16-Oct-06 13:59
memberBDisp16-Oct-06 13:59 
AnswerRe: It's work better with Regional Settings accordingly Pin
mon_compte_anti_spam19-Oct-06 23:20
membermon_compte_anti_spam19-Oct-06 23:20 
QuestionPublic StylesSheetFileManager? Pin
TarpanXt23-Aug-06 4:43
memberTarpanXt23-Aug-06 4:43 
AnswerRe: Public StylesSheetFileManager? Pin
Sylvain BLANCHARD24-Aug-06 19:55
memberSylvain BLANCHARD24-Aug-06 19:55 
GeneralRe: Public StylesSheetFileManager? Pin
TarpanXt25-Aug-06 4:53
memberTarpanXt25-Aug-06 4:53 
GeneralRe: Public StylesSheetFileManager? Pin
Sylvain BLANCHARD25-Aug-06 13:23
memberSylvain BLANCHARD25-Aug-06 13:23 
GeneralRe: Public StylesSheetFileManager? Pin
TarpanXt28-Aug-06 4:25
memberTarpanXt28-Aug-06 4:25 
GeneralRe: Public StylesSheetFileManager? Pin
Prince Hitech1-Sep-09 21:51
memberPrince Hitech1-Sep-09 21:51 
GeneralEnglish resource file? [modified] Pin
TarpanXt22-Aug-06 10:58
memberTarpanXt22-Aug-06 10:58 
GeneralRe: English resource file? Pin
Sylvain BLANCHARD25-Aug-06 13:25
memberSylvain BLANCHARD25-Aug-06 13:25 
GeneralIt's 2006, not 2005 Pin
Marc Clifton9-Aug-06 4:03
protectorMarc Clifton9-Aug-06 4:03 
GeneralRe: It's 2006, not 2005 Pin
Sylvain BLANCHARD9-Aug-06 22:34
memberSylvain BLANCHARD9-Aug-06 22:34 
Questiongood work, but the designer? Pin
emanuele.vicari20-Jul-06 2:35
memberemanuele.vicari20-Jul-06 2:35 
AnswerRe: good work, but the designer? Pin
Sylvain BLANCHARD21-Jul-06 10:04
memberSylvain BLANCHARD21-Jul-06 10:04 
GeneralRe: good work, but the designer? Pin
Olivier DALET7-Aug-06 21:53
memberOlivier DALET7-Aug-06 21:53 
GeneralRe: good work, but the designer? Pin
Sylvain BLANCHARD7-Aug-06 23:12
memberSylvain BLANCHARD7-Aug-06 23:12 
GeneralRe: good work, but the designer? Pin
Olivier DALET7-Aug-06 23:31
memberOlivier DALET7-Aug-06 23:31 
GeneralRe: good work, but the designer? Pin
emanuele.vicari27-Aug-06 23:23
memberemanuele.vicari27-Aug-06 23:23 
QuestionHow about the performance? Pin
yancyn17-Jul-06 16:16
memberyancyn17-Jul-06 16:16 
AnswerRe: How about the performance? Pin
mon_compte_anti_spam18-Jul-06 9:37
membermon_compte_anti_spam18-Jul-06 9:37 
GeneralRe: How about the performance? Pin
Sylvain BLANCHARD19-Jul-06 10:22
memberSylvain BLANCHARD19-Jul-06 10:22 
QuestionComplex Properties [modified] Pin
d0tnetdude14-Jul-06 12:22
memberd0tnetdude14-Jul-06 12:22 
AnswerRe: Complex Properties Pin
Sylvain BLANCHARD15-Jul-06 15:19
memberSylvain BLANCHARD15-Jul-06 15:19 
GeneralNice Work Pin
Atlas200214-Jul-06 6:24
memberAtlas200214-Jul-06 6:24 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151125.1 | Last Updated 25 Oct 2006
Article Copyright 2006 by Sylvain BLANCHARD
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid