Skip to main content

How To: Create New Character Style

The following example illustrates how to create a character style in code.

To achieve the required result, do the following:

View Example

document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
CharacterStyle cstyle = document.CharacterStyles["MyCStyle"];
if (cstyle == null)
{
    cstyle = document.CharacterStyles.CreateNew();
    cstyle.Name = "MyCStyle";
    cstyle.Parent = document.CharacterStyles["Default Paragraph Font"];
    cstyle.ForeColor = System.Drawing.Color.DarkOrange;
    cstyle.Strikeout = StrikeoutType.Double;
    cstyle.FontName = "Verdana";
    document.CharacterStyles.Add(cstyle);
}
DocumentRange myRange = document.Paragraphs[0].Range;
CharacterProperties charProps =
    document.BeginUpdateCharacters(myRange);
charProps.Style = cstyle;
document.EndUpdateCharacters(charProps);