Hi,

I have a RichTextBox1 and this code:

VB Code:
  1. Public ColorKeyword As Color = ColorTranslator.FromHtml("#a325a3")
  2.  
  3.     Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
  4.  
  5.         Dim Keywords As New List(Of String)
  6.         Keywords.Add("echo")
  7.         Keywords.Add("print")
  8.  
  9.         If RichTextBox1.Text.Length > 0 Then
  10.             Dim selectStart As Integer = RichTextBox1.SelectionStart
  11.             RichTextBox1.Select(0, RichTextBox1.Text.Length)
  12.             RichTextBox1.SelectionColor = Color.Black
  13.             RichTextBox1.DeselectAll()
  14.             For Each oneWord As String In Keywords
  15.                 Dim pos As Integer = 0
  16.                 Do While RichTextBox1.Text.ToUpper.IndexOf(oneWord.ToUpper, pos) >= 0
  17.                     pos = RichTextBox1.Text.ToUpper.IndexOf(oneWord.ToUpper, pos)
  18.                     RichTextBox1.Select(pos, oneWord.Length)
  19.                     RichTextBox1.SelectionColor = ColorKeyword
  20.                     pos += 1
  21.                 Loop
  22.             Next
  23.             RichTextBox1.SelectionLength = 0
  24.             RichTextBox1.SelectionStart = selectStart
  25.         End If
  26.  
  27.     End Sub

The code highlights nicely, but there is a problem.

Try the above code and you will notice how much it flickers/flashes. How would I avoid the flickering? Also, if I paste a big text like 10 000 lines and if I then go to the end of the document and start writing, everytime I write a new character it jumps to the start of the document.

Any help? I will give credits!