Skip to main content

How to: Insert Text at the Cursor Position

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

View Example

Document document = richEditControl.Document;
DocumentPosition pos = document.CaretPosition;
SubDocument doc = 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.