The TextPointer class is intended to facilitate traversal and manipulation of content in a RichTextBox. The TextPointer class introduces the following terminology:

Position - A TextPointer that points to a location in the content of a RichTextBox. A position either occurs between characters in the content, or between content element tags that define structure for the content.

Current Position - The position indicated by the current TextPointer. Many of the operations that can be performed with a TextPointer are relative to the current TextPointer position. Therefore, a position indicated by a TextPointer is typically referred to as the current position.

Insertion Position - A position where new content may be added without breaking any semantic rules for the associated content. In practice, an insertion position is anywhere in content where a caret may be positioned. An example of a valid TextPointer position that is not an insertion position is the position between two adjacent Paragraph tags (that is, between the closing tag of the preceding paragraph and the opening tag of the next paragraph).

Symbol - For TextPointer operations, any of the following is considered to be a symbol:

Text Container - The element that forms the border for the content. The position indicated by a TextPointer always occurs within a text container. Currently, a text container can only be a RichTextBox. Typically, operations between TextPointer instances in different text containers are not supported.

Some of the operations that TextPointer facilitates include the following:

Performing an ordinal comparison of the current position with a second specified position. For more information, see the CompareTo method.

The position and LogicalDirection indicated by a TextPointer object are immutable. When content is edited or modified, the position indicated by a TextPointer does not change relative to the surrounding text. Instead, the offset of that position from the beginning of content is adjusted correspondingly to reflect the new relative position in content. For example, a TextPointer that indicates a position at the beginning of a paragraph continues to point to the beginning of that paragraph even when content is inserted or deleted before or after the paragraph.

The TextPointer class does not provide any public constructors. An instance of TextPointer is created by using properties or methods of other objects (including other TextPointer objects). The following list provides a few examples of methods and properties that create and return a TextPointer. This list is not exhaustive:

The following code example highlights the first word and underlines the last word in the sentence that you type in the RichTextBox. In this example, a space character is used as the word boundary. The example will also identify if the RichTextBox is empty.