Dim searchword() As String = {"fox", "hound", "rat", "dog"}
Dim ItemBkColor() As Color = {Color.Yellow, Color.LightYellow, Color.PaleVioletRed, Color.LightSeaGreen}
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
Dim SelStart As Integer = RichTextBox1.SelectionStart
Dim count As Integer = 0
Dim srchMode As RichTextBoxFinds
srchMode = RichTextBoxFinds.WholeWord
For SearchWordPointer As Integer = 0 To searchword.Length - 1
Dim wordAt As Integer = 0
Do While wordAt <> -1
wordAt = RichTextBox1.Find(searchword(SearchWordPointer), wordAt, srchMode)
If wordAt = -1 Then
Exit Do
Else
HightlightLine(wordAt, ItemBkColor(SearchWordPointer))
wordAt += 1
count += 1
End If
Loop
Next
RichTextBox1.SelectionStart = SelStart
RichTextBox1.SelectionLength = 0
RichTextBox1.SelectionBackColor = Color.White
End Sub
Private Sub HightlightLine(ByVal wordat As Integer, ByVal BG_Color As Color)
Dim lineindex As Integer = Me.RichTextBox1.GetLineFromCharIndex(wordat)
Dim first As Integer = Me.RichTextBox1.GetFirstCharIndexFromLine(lineindex)
Dim last As Integer = Me.RichTextBox1.GetFirstCharIndexFromLine(lineindex + 1)
If last = -1 Then last = Me.RichTextBox1.TextLength
Me.RichTextBox1.Select(first, last - first)
Me.RichTextBox1.SelectionBackColor = BG_Color
End Sub