Back to Devexpress

How to: Append Text to the Paragraph

windowsforms-9902-controls-and-libraries-rich-text-editor-examples-text-how-to-append-text-to-the-paragraph.md

latest1.6 KB
Original Source

How to: Append Text to the Paragraph

  • Dec 12, 2022

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.

View Example: WinForms RichEdit Document API

csharp
Document document = richEditControl.Document;
document.BeginUpdate();
document.AppendText("First Paragraph\nSecond Paragraph\nThird Paragraph");
document.EndUpdate();

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>>");
pos.EndUpdateDocument(doc);
vb
document.BeginUpdate()
document.AppendText("First Paragraph" & vbLf & "Second Paragraph" & vbLf & "Third Paragraph")
document.EndUpdate()

Dim pos As DocumentPosition = document.CaretPosition
Dim doc As SubDocument = pos.BeginUpdateDocument()
Dim par As Paragraph = doc.Paragraphs.Get(pos)
Dim newPos As DocumentPosition = doc.CreatePosition(par.Range.End.ToInt() - 1)
doc.InsertText(newPos, "<<Appended to Paragraph End>>")
pos.EndUpdateDocument(doc)