Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How To: Create New Character Style

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

The following code snippet creates a new character style, specifies style settings, adds it to the document style collection and applies the style to the specified range.

View Example

richEditControl.Document.LoadDocument("Grimm.docx");

// Create a new style
CharacterStyle cstyle = richEditControl.Document.CharacterStyles.CreateNew();


// Specify style parameters
cstyle.Name = "MyCStyle";
cstyle.Parent = richEditControl.Document.CharacterStyles["Default Paragraph Font"];
cstyle.ForeColor = System.Drawing.Color.DarkOrange;
cstyle.Strikeout = StrikeoutType.Double;
cstyle.FontName = "Verdana";

// Add style to the collection
document.CharacterStyles.Add(cstyle);

// Obtain the second document paragraph
DocumentRange myRange = richEditControl.Document.Paragraphs[0].Range;

// Apply created style to the paragraph
CharacterProperties charProps =
    richEditControl.Document.BeginUpdateCharacters(myRange);
charProps.Style = cstyle;
richEditControl.Document.EndUpdateCharacters(charProps);