How To: Create New Linked Style

  • 2 minutes to read

This example explains how to create a linked style – a style that can be applied both to the character and paragraph, depending on the range to which it is applied.

To create such a style, follow the steps below.

  1. Create a new paragraph style.
  2. Create a new character style.
  3. Set the CharacterStyle.LinkedStyle to the newly created paragraph style, or set the ParagraphStyle.LinkedStyle property to the corresponding CharacterStyle object. It is sufficient to set only one of these properties.


All the actions should be performed using the SubDocument.BeginUpdate - SubDocument.EndUpdate paired methods. Otherwise, flickering might occur when starting the application.

The following code snippet demonstrates how to create linked styles.

View Example

document.AppendText("Line One\nLine Two\nLine Three");

//Create new paragraph style
ParagraphStyle lstyle = document.ParagraphStyles["MyLinkedStyle"];
if (lstyle == null)
    lstyle = document.ParagraphStyles.CreateNew();
    lstyle.Name = "MyLinkedStyle";
    lstyle.LineSpacingType = ParagraphLineSpacing.Double;
    lstyle.Alignment = ParagraphAlignment.Center;

    CharacterStyle lcstyle = document.CharacterStyles.CreateNew();
    lcstyle.Name = "MyLinkedCStyle";
    lcstyle.LinkedStyle = lstyle;

    lcstyle.ForeColor = System.Drawing.Color.DarkGreen;
    lcstyle.Strikeout = StrikeoutType.Single;
    lcstyle.FontSize = 24;

    //Apply created styles 
    //to the text range and to the entire paragraph
    document.Paragraphs[1].Style = lstyle;

    DocumentRange myRange = document.Paragraphs[0].Range;
    CharacterProperties charProps = document.BeginUpdateCharacters(myRange);
    charProps.Style = lcstyle;