Skip to main content

How to: Append Text to the Paragraph

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

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);