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

How to find paragraph under mouse

1 Answer 48 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 20 Feb 2013, 08:52 PM
Is there a way to determine which paragraph in a document the mouse is over when the user right-clicks?

1 Answer, 1 is accepted

Sort by
0
Accepted
Petya
Telerik team
answered on 25 Feb 2013, 02:28 PM
Hi John,

When right-clicking within a RadRichTextBox, the caret position is changed to the place where you clicked. So, you can obtain the paragraph using the CaretPosition. For example, here is how you can select it:
DocumentPosition start = new DocumentPosition(editor.Document);
DocumentPosition end = new DocumentPosition(editor.Document);
 
start.MoveToPosition(editor.Document.CaretPosition);
end.MoveToPosition(editor.Document.CaretPosition);
 
start.MoveToFirstPositionInParagraph();
end.MoveToLastPositionInParagraph();
 
editor.Document.Selection.AddSelectionStart(start);
editor.Document.Selection.AddSelectionEnd(end);

You can refer to the Positioning and Selection articles in our documentation for further information.

I hope this is helpful! If you have other questions, please do not hesitate to get back to us.
 
All the best,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
John
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or