PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Detecting words in richtextbox-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] Detecting words in richtextbox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    Resolved [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!

  2. #2
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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?

  4. #4
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Detecting words in richtextbox

    Try this, i have it changing the tooltiptext for each word.
    VB Code:
    1. Option Explicit
    2. Private Type POINTAPI
    3. x As Long
    4. y As Long
    5. End Type
    6.  
    7. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    8. (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    9. ByRef lParam As Any) As Long
    10.  
    11. Private Const EM_CHARFROMPOS& = &HD7
    12.  
    13.  
    14.  
    15. Private Sub rtb_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    16.  
    17. Dim pt As POINTAPI, pos As Long, c As String
    18. Dim s As Long, f As Long
    19.  
    20.  pt.x = x \ Screen.TwipsPerPixelX
    21.  pt.y = y \ Screen.TwipsPerPixelY
    22.    
    23.  pos = SendMessage(rtb.hWnd, EM_CHARFROMPOS, 0&, pt)
    24.  If pos <= 0 Then Exit Sub
    25.  
    26.  For s = pos To 1 Step -1
    27.    c = Mid$(rtb.Text, s, 1)
    28.    Select Case c
    29.     Case "a" To "z", "A" To "Z", "0" To "9" 'add to this line you will accept
    30.     Case Else
    31.      Exit For
    32.    End Select
    33.  Next s
    34.  
    35.  s = s + 1
    36.  
    37.  For f = pos To Len(rtb.Text)
    38.    c = Mid$(rtb.Text, f, 1)
    39.    Select Case c
    40.     Case "a" To "z", "A" To "Z", "0" To "9" 'add to this line you will accept
    41.     Case Else
    42.      Exit For
    43.    End Select
    44.  Next f
    45.  
    46. f = f - 1
    47.  
    48. If s <= f Then
    49.  rtb.ToolTipText = Mid$(rtb.Text, s, f - s + 1)
    50. End If
    51.  
    52. End Sub

    casey.

  5. #5
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    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
  •  



Featured


Click Here to Expand Forum to Full Width