06-18-2012, 06:00 PM
Here is a nice control that will handle that for you, if you don't want to program it yourself.
<!-- m --><a class="postlink" href="http://www.freevbcode.com/ShowCode.asp?ID=5176">http://www.freevbcode.com/ShowCode.asp?ID=5176</a><!-- m -->
But if you do want to program it yourself, it should look something like this:
<!-- m --><a class="postlink" href="http://www.freevbcode.com/ShowCode.asp?ID=5176">http://www.freevbcode.com/ShowCode.asp?ID=5176</a><!-- m -->
But if you do want to program it yourself, it should look something like this:
Code:
Public Sub HighlightKeyWords(ByVal rtb As RichTextBox, ByVal words As List(Of String))
Dim selection_original As Integer = rtb.SelectionStart
For Each word As String In words
If (rtb.Text.Contains(word)) Then
Dim pos As Integer = rtb.Find(word)
If (pos <> -1) Then
'The value was found and now has a position
rtb.Select(pos, word.Length)
rtb.SelectionColor = Color.Blue
'Now go back to our original selection
rtb.Select(selection_original, 0)
End If
End If
Next
End Sub