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

Word under cursor

1 Answer 88 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 20 Apr 2018, 09:24 PM

I'm starting to play around with the Telerik RTB and I was wondering if there was a way to get the word under the mouse cursor?

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 24 Apr 2018, 03:07 PM
Hello Kyle,

You can obtain the word at a document position using the GetCurrentWord() method. To get the DocumentPosition corresponding to the mouse position at the moment, you can use the GetDocumentPositionFromViewPoint() method. Here is a simple example:

private void RadRichTextBox_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    DocumentPosition position = this.radRichTextBox.ActiveEditorPresenter.GetDocumentPositionFromViewPoint(e.GetPosition(this.radRichTextBox));
    string word = position.GetCurrentWord();
}

And if you would like to directly work with the position of the document caret, you can use it like this:

string word = this.radRichTextBox.Document.CaretPosition.GetCurrentWord();

Hope this helps.

Regards,
Tanya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RichTextBox
Asked by
Kyle
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or