Get word under mouse

Is it possible to get text under mouse cursor when viewing a pdf file?

Are you using PDFViewCtrl (or PDFViewWPF) class? Also what platform (Android, etc.)?

Also, mouse cursor is just a point? Typically text selection is using two points.

Finally, are you looking for just a single character that intersects the point? Or a while word?

It would be great if you could provide a use case, and describe the result you want.

  1. I have downloaded the trial version for .net 2.0 + 3.5 and using it with Visual Basic .Net

  1. In RichTextBox we can get GetCharIndexFromPosition(e.Location)
Public cursorAt As Integer
    Public wordEnd As Integer
    Public isEnd As Boolean
    Public wordStart As Integer
cursorAt = RichTextBox1.GetCharIndexFromPosition(e.Location)
       If cursorAt = 0 Then Return
       wordEnd = New Regex("[\s$]{1}").Match(RichTextBox1.Text.Substring(cursorAt)).Index
       isEnd = Not New Regex("\s").IsMatch(RichTextBox1.Text.Substring(cursorAt))
       wordStart = New Regex("[\s^]{1}", RegexOptions.RightToLeft).Match(RichTextBox1.Text.Substring(0, cursorAt)).Index
       If isEnd Then
 RichTextBox1.Select(wordStart, RichTextBox1.Text.Length)
          RichTextBox1.Select(wordStart, cursorAt - wordStart + wordEnd)

       End If

3. Looking for whole world.

4. Want to make a dictionary which could provide meanings of word under mouse click.

  1. I have downloaded the trial version for .net 2.0 + 3.5 and using it with Visual Basic .Net

How are you “clicking” on the PDF? Are you using our PDFViewCtrl class to display and interact with the PDF? Or are you doing this through some other means (if so please describe).

Thanks for your time, I am using PDFViewCtrl. Suppose a pdf file is opened in PDFViewCtrl and user is reading that file.
In the meantime he want to know meanings of any word written in pdf file. I want him to just click on the word and I will show him meaning. Now I wan to get the word under cursor in PDFViewCtrl.

Also I am unable to catch below events. It seems they are not fired.

Private Sub _pdfview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _pdfview.Click

End Sub

Private Sub _pdfview_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _pdfview.DoubleClick

End Sub

Private Sub _pdfview_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _pdfview.MouseDoubleClick

End Sub

Since you are using PDFViewCtrl, then the best thing to do is using the PDFViewCtrl.Select method. This will take care of all sorts of things for you, such as selecting whole words.

For the two pairs of points, I would define them such that you have a small rectangle around the mouse point.

Regarding the events, please see this forum post.

Thanks this helped. I have a some more questions.
How I can detect when user highlighted some text or added a sticky note? All I can found is “_pdfview.GetDoc.IsModified()” property but when to call this property to check for modification? I mean if I use a timer to always check if it is modified or not?

When user highlight some text and wants to add a comment or note to that highlight by double clicking on the highlight text the popup box not appeared at the corner of screen with no visible textbox. However, it is working fine when we add a note.

Is there anyway I can replace the popup form of notes?

How to find a note by unique id and set it to open? I had tried the following code with no luck.

If type = Annot.Type.e_Text Then
Dim txt As pdftron.PDF.Annots.Text = New pdftron.PDF.Annots.Text(ann)
End If