RadRichTextBox does not use integer indexes for the positions in the document. Instead, it uses document positions, which enable you to go to specific document elements. This is particularly convenient when you want to do some formatting, as most methods and commands are executed on selection or the elements at the current caret position, which is also a document position.
You can get the current caret position like this:
When you click inside the document, the caret position will change to the place in the document you have clicked.
DocumentPosition caretPosition =
As for obtaining the position of a Bookmark, this can be done through document positions as well. Some information on the methods that RadRichTextBox and RadDocument expose with relation to bookmarks can be found here
. Obtaining a document position that is at the beginning or end of a bookmark, can be done like this:
DocumentPosition start =
DocumentPosition end =
//DocumentPosition pointing to the beginning of the bookmark
//DocumentPosition pointing to the end of the bookmark
Getting the line number of a document position can be done as shown in this forum post
. You can perform some similar logic for counting the positions between the start of the line to the start of the bookmark in order to achieve the behavior you are after.
Obtaining the page number when the user clicks in the document can be done like this:
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>