# Using a Cascading Style Sheet with C1Editor

Learn how to use cascading style sheet in C1Editor for WinForms control.

## Content



1.  Create a .NET project and add a [C1Editor](/componentone/api/win/online-richtexteditor/dotnet-framework-api/C1.Win.C1Editor.4.8/C1.Win.C1Editor.C1Editor.html) and **Button** control to the form.
2.  In the Solution Explorer, double-click **Resources.resx**, click **Add Resource**, and select **Add New String**.
3.  Enter **sEditorText** as the **Name** of the resource.
4.  In the **Value** column, enter some content for the .xml document. You can copy this sample content and enter it if you prefer.
    
    DOC-DETAILS-TAG-OPEN
    
    DOC-SUMMARY-TAG-OPEN
    
    Sample content
    
    DOC-SUMMARY-TAG-CLOSE
    
    \<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html SYSTEM<br />"C:\\Users\\jjj\\AppData\\Local\\Temp\\tmpB1BB.tmp"[\]><html<br />xmlns="http://www.w3.org/1999/xhtml">\<head>\<title>Famous<br />Pittsburgers\</title><meta http-equiv="Content-Type"<br />content="text/html; charset=utf-8" />\</head>\<body>\<h1>Famous<br />Pittsburghers\</h1>\<p class="BodyText">Many famous and successful<br />people were born and raised in Pittsburgh; although they found<br />fame in other cities, they called Pittsburgh home.\</p><p<br />class="C1SectionCollapsed">Actors/Comedians\</p>\<ul>\<li><p<br />class="C1HBullet">Gene Kelly (Dancer and star of "Singin' in the<br />Rain")\</p>\</li>\<li>\<p class="C1HBullet">Michael Keaton (Star of<br />"Batman," "Mr. Mom," and many other movies)\</p>\</li>\<li><p<br />class="C1HBullet">Dennis Miller ("Saturday Night Live" cast<br />member and TV/radio talk show host) \</p>\</li>\</ul><p<br />class="C1SectionCollapsed">TV Legend\</p>\<ul>\<li><p<br />class="C1HBullet">Fred Rogers (Producer and host of PBS's "Mister<br />Rogers' Neighborhood")\</p>\</li>\</ul><p<br />class="C1SectionCollapsed">Artists\</p>\<ul>\<li><p<br />class="C1HBullet">Mary Cassatt (Impressionist<br />painter)\</p>\</li>\<li>\<p class="C1HBullet">Andy Warhol (Pop<br />artist; Pittsburgh is the home of the Andy Warhol Museum)<br />\</p>\</li>\</ul>\<p class="C1SectionCollapsed">Sports<br />Legends\</p>\<ul>\<li>\<p class="C1HBullet">Dan Marino (Quarterback<br />of the Miami Dolphins and University of Pittsburgh<br />Panthers)\</p>\</li>\<li>\<p class="C1HBullet">Joe Montana (Super<br />Bowl champion quarterback of the San Francisco<br />49ers)\</p>\</li>\<li>\<p class="C1HBullet">Joe Namath (Outspoken New<br />York Jets quarterback; victorious in Super Bowl<br />III)\</p>\</li>\<li>\<p class="C1HBullet">Johnny Unitas (Quarterback<br />of the Baltimore Colts for 17 years)\</p>\</li>\<li><p<br />class="C1HBullet">Arnold Palmer (Golf legend and winner of more<br />than 60 PGA events, including the Masters and the U.S.<br />Open)\</p>\</li>\</ul><p<br />class="C1SectionCollapsed">Singers\</p>\<ul>\<li><p<br />class="C1HBullet">Perry Como (Recorded over 100 hit<br />singles)\</p>\</li>\<li>\<p class="C1HBullet">Bobby Vinton ("Roses<br />are Red" and "Blue Velvet" hit #1 on the Billboard<br />charts)\</p>\</li>\</ul><p<br />class="C1SectionCollapsed">Writers\</p>\<ul>\<li><p<br />class="C1HBullet">Rachel Carson (Author of "Silent Spring," as<br />well as a pioneering<br />environmentalist)\</p>\</li>\</ul>\</body>\</html><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    
    DOC-DETAILS-TAG-CLOSE
    
5.  Go back to your form and double-click it.
6.  In the **Form\_Load** event, enter code to load the .xml document so it looks like the following:
    
    DOC-DETAILS-TAG-OPEN
    
    DOC-SUMMARY-TAG-OPEN
    
    To write code in C#
    
    DOC-SUMMARY-TAG-CLOSE
    
    ```csharp
    private void Form1_Load(object sender, EventArgs e)
            {
                c1Editor1.LoadXml(Resources.sEditorText, null);
            }
    ```
    
    DOC-DETAILS-TAG-CLOSE
    

### Load a CSS

1.  Create a CSS and add it to your project by right-clicking the project name in the Solution Explorer, select **Add Existing Item**, choosing the CSS, and clicking **Add**. You can use this sample CSS if you don't already have one.
    
    DOC-DETAILS-TAG-OPEN
    
    DOC-SUMMARY-TAG-OPEN
    
    Sample CSS
    
    DOC-SUMMARY-TAG-CLOSE
    
    ```auto
    html {
    ```
    
    ```auto
           font-family: Verdana;
    ```
    
    ```auto
           font-size: 10pt;
    ```
    
    ```auto
           line-height: normal;
    ```
    
    ```auto
           margin-bottom: 0pt;
    ```
    
    ```auto
           margin-left: 0pt;
    ```
    
    ```auto
           margin-right: 0pt;
    ```
    
    ```auto
           margin-top: 0pt;
    ```
    
    ```auto
    }
    ```
    
    ```auto
     
    ```
    
    ```auto
    h1 {
    ```
    
    ```auto
           font-family: Verdana;
    ```
    
    ```auto
           font-size: 20pt;
    ```
    
    ```auto
           font-weight: bold;
    ```
    
    ```auto
           line-height: normal;
    ```
    
    ```auto
           margin-bottom: 8pt;
    ```
    
    ```auto
           margin-left: 0pt;
    ```
    
    ```auto
           margin-right: 0pt;
    ```
    
    ```auto
           margin-top: 10pt;
    ```
    
    ```auto
    }
    ```
    
    ```auto
     
    ```
    
    ```auto
    h2 {
    ```
    
    ```auto
           font-family: Verdana;
    ```
    
    ```auto
           font-size: 16pt;
    ```
    
    ```auto
           font-weight: bold;
    ```
    
    ```auto
           line-height: normal;
    ```
    
    ```auto
           margin-bottom: 7pt;
    ```
    
    ```auto
           margin-left: 0pt;
    ```
    
    ```auto
           margin-right: 0pt;
    ```
    
    ```auto
           margin-top: 9pt;
    ```
    
    ```auto
           page-break-after: avoid;
    ```
    
    ```auto
    }
    ```
    
    ```auto
     
    ```
    
    ```auto
    h3 {
    ```
    
    ```auto
           font-family: Verdana;
    ```
    
    ```auto
           font-size: 16pt;
    ```
    
    ```auto
           font-weight: bold;
    ```
    
    ```auto
           line-height: normal;
    ```
    
    ```auto
           margin-bottom: 7pt;
    ```
    
    ```auto
           margin-left: 0pt;
    ```
    
    ```auto
           margin-right: 0pt;
    ```
    
    ```auto
           margin-top: 9pt;
    ```
    
    ```auto
           page-break-after: avoid;
    ```
    
    ```auto
    }
    ```
    
    ```auto
     
    ```
    
    ```auto
    h4 {
    ```
    
    ```auto
           font-family: Verdana;
    ```
    
    ```auto
           font-size: 12pt;
    ```
    
    ```auto
           font-weight: bold;
    ```
    
    ```auto
           line-height: normal;
    ```
    
    ```auto
           margin-bottom: 2pt;
    ```
    
    ```auto
           margin-left: 0pt;
    ```
    
    ```auto
           margin-right: 0pt;
    ```
    
    ```auto
           margin-top: 2pt;
    ```
    
    ```auto
           page-break-after: avoid;
    ```
    
    ```auto
    }
    ```
    
    ```auto
     
    ```
    
    ```auto
    .C1HBullet {
    ```
    
    ```auto
           font-family: Verdana;
    ```
    
    ```auto
           font-size: 10pt;
    ```
    
    ```auto
            font-style: italic;
    ```
    
    ```auto
           line-height: 14pt;
    ```
    
    ```auto
           margin-bottom: 0pt;
    ```
    
    ```auto
           margin-left: 18pt;
    ```
    
    ```auto
           margin-right: 0pt;
    ```
    
    ```auto
           margin-top: 5pt;
    ```
    
    ```auto
           text-indent: -18pt;
    ```
    
    ```auto
    }
    ```
    
    ```auto
     
    ```
    
    ```auto
    p {
    ```
    
    ```auto
           font-family: Verdana;
    ```
    
    ```auto
           font-size: 10pt;
    ```
    
    ```auto
           line-height: 14pt;
    ```
    
    ```auto
           margin-bottom: 0pt;
    ```
    
    ```auto
           margin-left: 0pt;
    ```
    
    ```auto
           margin-right: 0pt;
    ```
    
    ```auto
           margin-top: 5pt;
    ```
    
    ```auto
            text-indent: 18pt;
    ```
    
    ```auto
    }
    ```
    
    ```auto
     
    ```
    
    ```auto
    .C1SectionCollapsed {
    ```
    
    ```auto
           font-weight: bold;
    ```
    
    ```auto
    }
    ```
    
    DOC-DETAILS-TAG-CLOSE
    
2.  Add a **button1\_Click** event and use the [LoadDesignCSS](/componentone/api/win/online-richtexteditor/dotnet-framework-api/C1.Win.C1Editor.4.8/C1.Win.C1Editor.C1Editor.LoadDesignCSS.html) method:
    
    DOC-DETAILS-TAG-OPEN
    
    DOC-SUMMARY-TAG-OPEN
    
    To write code in C#
    
    DOC-SUMMARY-TAG-CLOSE
    
    ```csharp
    privatevoid button1_Click(object sender, EventArgs e)
           {
               c1Editor1.LoadDesignCSS(@"C:\CSS1.css");
           }
    ```
    
    DOC-DETAILS-TAG-CLOSE
    

### Run the Project

1.  Press F5 to run the project. Notice the document is loaded in the C1Editor.
2.  Click the button. The document is formatted with the CSS.

For a detailed example of using custom cascading style sheets, see the **UserCSS** sample that comes with this product.