Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

ParagraphStyle Interface

Exposes methods and characteristics of a paragraph style in a document.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v19.2.Core.dll

Declaration

[ComVisible(true)]
public interface ParagraphStyle :
    ParagraphPropertiesWithTabs,
    ParagraphPropertiesBase,
    CharacterPropertiesBase

Remarks

Use the paragraph style to change both character (a font type, size, color, etc.) and paragraph (alignment, spacing before and after, etc.) attributes as in the current example. RichEditDocumentServer doesn’t have any predefined document styles. Use members from the table below to create a new document style.

The code sample below demonstrates creates a new paragraph style and apply it to every chapter.

IMAGE

//Open the document for editing
document.BeginUpdate();

//Create a new paragraph style instance
//and specify the required properties
ParagraphStyle chapterStyle = document.ParagraphStyles.CreateNew();
chapterStyle.Name = "MyTitleStyle";
chapterStyle.ForeColor = Color.SteelBlue;
chapterStyle.FontSize = 16;
chapterStyle.FontName = "Segoe UI Semilight";
chapterStyle.Alignment = ParagraphAlignment.Left;
chapterStyle.SpacingBefore = Units.InchesToDocumentsF(0.2f);
chapterStyle.SpacingAfter = Units.InchesToDocumentsF(0.2f);
chapterStyle.OutlineLevel = 2;

//Add the object to the document collection
document.ParagraphStyles.Add(chapterStyle);

//Finalize the editing
document.EndUpdate();

//Apply the created style to every chapter in the document 
for (int i = 0; i < document.Paragraphs.Count; i++)
{
    string var = document.GetText(document.Paragraphs[i].Range);
    if (var.Contains("Chapter "))
    {
        document.Paragraphs[i].Style = chapterStyle;
    }
}
return;

If the loaded document already has document styles, they are automatically added to the document’s CharacterStyleCollection or ParagraphStyleCollection and you can use them as shown in the code snippet below.

//Apply style to the paragraph
richEditDocumentServer1.Document.Paragraphs[1].Style = richEditDocumentServer1.Document.ParagraphStyles["Heading 2"];

//Apply style to the character range
DocumentRange range = richEditDocumentServer1.Document.Paragraphs[1].Range;
CharacterProperties rangeProperties = richEditDocumentServer1.Document.BeginUpdateCharacters(range);
rangeProperties.Style = richEditDocumentServer1.Document.CharacterStyles["Heading 2"];
richEditDocumentServer1.Document.EndUpdateCharacters(rangeProperties);

Tip

Load an empty document created in Microsoft® Word® using the Document.LoadDocument method in the RichEditDocumentServer.EmptyDocumentCreated event handler to fill the collection of a newly created document with the predefined styles.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ParagraphStyle interface.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also