.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Paragraph Class

Represents a single paragraph in a document.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v21.1.Core.dll


public abstract class Paragraph


All paragraphs in a document are represented by the ParagraphCollection, accessible via the SubDocument.Paragraphs property. A document Section contains a collection of paragraphs and provides the Section.Paragraphs property to access it.

To modify formatting for a paragraph which encompasses the specified range, get a SubDocument interface for this range first. For this purpose, you can use the DocumentPosition.BeginUpdateDocument - DocumentPosition.EndUpdateDocument or the DocumentRange.BeginUpdateDocument - DocumentRange.EndUpdateDocument method pairs.

Then, use the SubDocument.BeginUpdateParagraphs - SubDocument.EndUpdateParagraphs paired methods. The SubDocument.BeginUpdateParagraphs method requires a DocumentRange as the parameter, and returns a ParagraphProperties interface which exposes formatting properties for this range.

To modify the text of the paragraph, you can use its SubDocument methods. For example, to append a text to the current paragraph, use the technique illustrated below.

The following code snippet appends text to the end of the current paragraph. Note that the DocumentPosition.BeginUpdateDocument call is required for proper operation within header/footer since it returns a SubDocument interface.

Document document = server.Document;
document.AppendText("First Paragraph\nSecond Paragraph\nThird Paragraph");
DocumentPosition pos = document.CaretPosition;
SubDocument doc = pos.BeginUpdateDocument();
Paragraph par = doc.Paragraphs.Get(pos);
DocumentPosition newPos = doc.CreatePosition(par.Range.End.ToInt() - 1);
doc.InsertText(newPos, "<<Appended to Paragraph End>>");


See Also