|
-
Jan 9th, 2006, 01:40 AM
#1
Thread Starter
Junior Member
[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!
-
Jan 9th, 2006, 03:20 AM
#2
Fanatic Member
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?
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Jan 9th, 2006, 03:23 AM
#3
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?
-
Jan 9th, 2006, 04:02 AM
#4
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.
-
Jan 9th, 2006, 04:26 AM
#5
Fanatic Member
Re: Detecting words in richtextbox
casey's code seems to be the one your looking for just pattern it to the conditions you want...
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Jan 9th, 2006, 04:56 AM
#6
Thread Starter
Junior Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|