VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Highlight words in RichTextBox using this simple function. This function requires 3 parameters to w

by Tim O (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 27th March 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Highlight words in RichTextBox using this simple function. This function requires 3 parameters to work, the RichTextBox as an object, the word

API Declarations


'This is highlight all occurances of paramter 2

'LockWindowUpdate used to prevent flickering as text is highlighted
Private Declare Function LockWindowUpdate Lib "user32" (ByVal thWnd As Long) As Long

Rate Highlight words in RichTextBox using this simple function. This function requires 3 parameters to w



    Dim cStart As Long: cStart = 1
    With tRich
        LockWindowUpdate .hWnd
        Dim sStart As Long, sLen As Long: sStart = .SelStart: sLen = .SelLength
        cStart = (InStr(cStart, LCase(.Text), tWord) - 1)
        Do While cStart <> -1
            .SelStart = cStart
            .SelLength = Len(tWord)
            .SelColor = tColor
            If Len(.Text) > (cStart + Len(tWord)) Then
                cStart = (InStr((cStart + Len(tWord)), LCase(.Text), tWord) - 1)
            Else
                cStart = -1
            End If
        Loop
        .SelStart = sStart
        .SelLength = sLen
        LockWindowUpdate 0
    End With
End Function

Download this snippet    Add to My Saved Code

Highlight words in RichTextBox using this simple function. This function requires 3 parameters to w Comments

No comments have been posted about Highlight words in RichTextBox using this simple function. This function requires 3 parameters to w. Why not be the first to post a comment about Highlight words in RichTextBox using this simple function. This function requires 3 parameters to w.

Post your comment

Subject:
Message:
0/1000 characters