RichTextBox.CaretPosition Property


Gets or sets the position of the input caret.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

Public Property CaretPosition As TextPointer

Property Value

Type: System.Windows.Documents.TextPointer

A TextPointer object specifying the position of the input caret.

By default, the caret is at the first insertion position at the beginning of the content hosted by the RichTextBox. See TextPointer for more information on text position terminology like "insertion position".

Exception Condition

An attempt is made to set this property to null.


An attempt is made to set this property to a TextPointer that references a position outside of the current document.

The following example illustrates the use of this property.

' Create a new FlowDocument, and add 3 paragraphs.
Dim flowDoc As New FlowDocument()
flowDoc.Blocks.Add(New Paragraph(New Run("Paragraph 1")))
flowDoc.Blocks.Add(New Paragraph(New Run("Paragraph 2")))
flowDoc.Blocks.Add(New Paragraph(New Run("Paragraph 3")))
' Set the FlowDocument to be the content for a new RichTextBox.
Dim rtb As New RichTextBox(flowDoc)

' Get the current caret position.
Dim caretPos As TextPointer = rtb.CaretPosition

' Set the TextPointer to the end of the current document.
caretPos = caretPos.DocumentEnd

' Specify the new caret position at the end of the current document.
rtb.CaretPosition = caretPos

.NET Framework
Available since 3.0
Return to top