[RESOLVED] Detecting words in richtextbox
I have a richtextbox on the form. When I move the mouse cursor over the words in the richtextbox, I what the program to detect which word the mouse cursor is on (without clicking the mouse button) or get the index of that position in the richtextbox. Can VB do this?
Thanks for help! :rolleyes:
Re: Detecting words in richtextbox
i really want to help you out in this but will you try to clarify what you want? will it be on highlight? or just on mouse over?
Re: Detecting words in richtextbox
VB can do that, but can't relay the index you want, without clarifying what you're looking for. What are you trying to do, when you hover over a word, without clicking it?
Re: Detecting words in richtextbox
Try this, i have it changing the tooltiptext for each word.
VB Code:
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByRef lParam As Any) As Long
Private Const EM_CHARFROMPOS& = &HD7
Private Sub rtb_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim pt As POINTAPI, pos As Long, c As String
Dim s As Long, f As Long
pt.x = x \ Screen.TwipsPerPixelX
pt.y = y \ Screen.TwipsPerPixelY
pos = SendMessage(rtb.hWnd, EM_CHARFROMPOS, 0&, pt)
If pos <= 0 Then Exit Sub
For s = pos To 1 Step -1
c = Mid$(rtb.Text, s, 1)
Select Case c
Case "a" To "z", "A" To "Z", "0" To "9" 'add to this line you will accept
Case Else
Exit For
End Select
Next s
s = s + 1
For f = pos To Len(rtb.Text)
c = Mid$(rtb.Text, f, 1)
Select Case c
Case "a" To "z", "A" To "Z", "0" To "9" 'add to this line you will accept
Case Else
Exit For
End Select
Next f
f = f - 1
If s <= f Then
rtb.ToolTipText = Mid$(rtb.Text, s, f - s + 1)
End If
End Sub
casey.
Re: Detecting words in richtextbox
casey's code seems to be the one your looking for just pattern it to the conditions you want...
Re: Detecting words in richtextbox
Thank you, casey, lerroux and David. Casey's code did work. That's really cool. I really appreciate for your help! :afrog: