This is a migrated thread and some comments may be shown as answers.

cursor current position for radrichtextbox?

3 Answers 591 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Shiv
Top achievements
Rank 1
Shiv asked on 09 May 2012, 09:50 PM
How to get the cursor current position for radrichtextbox?

like the Silver light control text box has property SelectionStart to get the current position of the cursor.

3 Answers, 1 is accepted

Sort by
0
Ivailo Karamanolev
Telerik team
answered on 11 May 2012, 09:36 AM
Hello,

You can access the current caret position through the RadDocument.CaretPosition property. More on this you can learn in the online help articles on positioning and selection.

Greetings,
Ivailo Karamanolev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Brian
Top achievements
Rank 1
answered on 18 May 2012, 05:21 PM

I am having an issue with positioning the cursor via the .MoveToPosition() method.  When I do this, the cursor gets placed correctly, but the document window adjusts so that the cursor is the last line that is shown. 

For example, my RadRichTextBox displays 10 lines at any given time and I have 50 lines of text in the document.  If I move the cursor to a place in the text that is on the 30th line, it will put the 30th line at the bottom of the display.  I would like for it to put the selected line in the middle of the displayed area OR not move the display at all, just move the cursor.

Hope this makes sense....

Tks.

0
Andrew
Telerik team
answered on 23 May 2012, 12:58 PM
Hi Brian,

A ready-to-use method for such functionality is not available out of the box. However you can use the following code:

DocumentPosition positionYouWantTheCaretOn = ...//logic finding the needed position
this.editor.Document.CaretPosition.MoveToPosition(positionYouWantTheCaretOn );
this.editor.ScrollToVerticalOffset(this.editor.Document.CaretPosition.Location.Y - this.editor.ActualHeight / 2);

I hope this helps.

Greetings,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Shiv
Top achievements
Rank 1
Answers by
Ivailo Karamanolev
Telerik team
Brian
Top achievements
Rank 1
Andrew
Telerik team
Share this question
or