How to find paragraph under mouse

2 posts, 1 answers
  1. John
    John avatar
    8 posts
    Member since:
    Jul 2012

    Posted 20 Feb 2013 Link to this post

    Is there a way to determine which paragraph in a document the mouse is over when the user right-clicks?
  2. Answer
    Petya
    Admin
    Petya avatar
    975 posts

    Posted 25 Feb 2013 Link to this post

    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.

  3. DevCraft banner
Back to Top