Hi,
I have a RichTextBox1 and this code:
VB Code:
Public ColorKeyword As Color = ColorTranslator.FromHtml("#a325a3") Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged Dim Keywords As New List(Of String) Keywords.Add("echo") Keywords.Add("print") If RichTextBox1.Text.Length > 0 Then Dim selectStart As Integer = RichTextBox1.SelectionStart RichTextBox1.Select(0, RichTextBox1.Text.Length) RichTextBox1.SelectionColor = Color.Black RichTextBox1.DeselectAll() For Each oneWord As String In Keywords Dim pos As Integer = 0 Do While RichTextBox1.Text.ToUpper.IndexOf(oneWord.ToUpper, pos) >= 0 pos = RichTextBox1.Text.ToUpper.IndexOf(oneWord.ToUpper, pos) RichTextBox1.Select(pos, oneWord.Length) RichTextBox1.SelectionColor = ColorKeyword pos += 1 Loop Next RichTextBox1.SelectionLength = 0 RichTextBox1.SelectionStart = selectStart End If 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!




Reply With Quote