Back to Devexpress

How to: Insert Text at the Cursor Position

windowsforms-5919-controls-and-libraries-rich-text-editor-examples-text-how-to-insert-text-at-the-cursor-position.md

latest1.2 KB
Original Source

How to: Insert Text at the Cursor Position

  • Dec 12, 2022

The following code snippet demonstrates how to insert text at the cursor position in the RichEditControl document:

View Example

csharp
Document document = richEditControl.Document;
DocumentPosition pos = document.CaretPosition;
SubDocument doc = pos.BeginUpdateDocument();
doc.InsertText(pos, " INSERTED TEXT ");
pos.EndUpdateDocument(doc);
vb
Dim document As Document = richEditControl.Document
Dim pos As DocumentPosition = document.CaretPosition
Dim doc As SubDocument = pos.BeginUpdateDocument()
doc.InsertText(pos, " INSERTED TEXT ")
pos.EndUpdateDocument(doc)

Tip

You can insert text at the cursor position within a text box. Use the TextBox.Document property to obtain text box content. Refer to the following topic for more information: Create a Text Box.