# Bold, Italic, Underline, Clear Formatting

Easily implement bold, italic, underline, and clear formatting commands in C1Editor for WinForms control.

## Content



The bold, italic, underline, and clear formatting commands are very easy to implement, they simply delegate the command to corresponding methods in the [C1Editor](/componentone/api/win/online-richtexteditor/dotnet-framework-api/C1.Win.C1Editor.4.8/C1.Win.C1Editor.C1Editor.html):

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
void Bold_Click(object sender, EventArgs e)
{
    _btnBold.Checked = SelectionFontBold = !SelectionFontBold;
}
void Italic_Click(object sender, EventArgs e)
{
    _btnItalic.Checked = SelectionFontItalic = !SelectionFontItalic;
}
void Underline_Click(object sender, EventArgs e)
{
    _btnUnderline.Checked = SelectionFontUnderline = !SelectionFontUnderline;
}
void ClearFormatting_Click(object sender, EventArgs e)
{
    Selection s = Editor.Selection;
    s.ClearFormatting();
}
```

DOC-DETAILS-TAG-CLOSE

The first three commands use helper properties defined by the **ToolStripStyles** class: **SelectionFontBold**, **SelectionFontItalic**, and **SelectionFontUnderline**. These helper properties are implemented as follows:

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
private bool SelectionFontBold
{
    get 
    { 
        return Editor.Mode == EditorMode.Design 
            ? Editor.Selection.IsTagApplied("strong") 
            : false; 
    }
    set
    {
        if (value)
        {
            Editor.Selection.ApplyTag("strong");
        }
        else
        {
            Editor.Selection.RemoveTag("strong");
        }
    }
}
```

DOC-DETAILS-TAG-CLOSE

The implementation uses the **C1Editor**'s [Selection](/componentone/api/win/online-richtexteditor/dotnet-framework-api/C1.Win.C1Editor.4.8/C1.Win.C1Editor.C1Editor.Selection.html) property, which returns a **Selection** object that represents the current selection. The **Selection** object has methods to apply, remove, and check whether formatting tags are applied to the selection.

The same logic used above is used to implement the **SelectionFontItalic** and **SelectionFontUnderline** helper properties.