I can't use that code because I'm making a syntax highlighter.
After highlighting the rest of the words will become the color and it highlight the keyword.
If i type anything else it will replace the highlighted word.
I think my code works fine. I was just trying to give you the general idea. But to make it even more clear,I'll integrate my code with yours:
Public Function Highlight(ByVal highlightcolor As String, ByVal ParamArray WordsToFind() As Object) 'Loop through all the words you specified: For i As Integer = 0 To UBound(WordsToFind) Dim Keyword As String = WordsToFind(i) 'Determine which color the word must become: Dim currentPositionOfCursor As Int32 = 0 Do Dim posOfNextHit As Int32 = RichTextBox1.Find(Keyword, currentPositionOfCursor, RichTextBoxFinds.None) If posOfNextHit >= currentPositionOfCursor Then Select Case highlightcolor Case "red" RichTextBox1.SelectionColor = Color.Red Case "blue" RichTextBox1.SelectionColor = Color.Blue Case "green" RichTextBox1.SelectionColor = Color.Green End Select RichTextBox1.Select(posOfNextHit, Keyword.Length) currentPositionOfCursor = posOfNextHit + 1 'reset the selection RichTextBox1.SelectionLength = 0 Else : Exit Do End If Loop Next i Return 1 End Function