[RESOLVED] [2008] RichTextbox syntax highlighting
I have a richtextbox on my form and currently have made a simple syntax highlighting for it. It works great with a small amount of text but as the text amount increases it starts flashing and locks the textbox while typing.
This is my current code. I call the sub on the textchanged event.
Basically what happens is I have a list of words that it checks for and if it finds it, it colors the word.
Code:
Sub ColorCode()
Dim selectStart As Integer = rtbCode.SelectionStart
rtbCode.Select(0, rtbCode.Text.Length)
rtbCode.SelectionColor = Color.Black
rtbCode.DeselectAll()
For Each oneWord As String In event_list
Dim pos As Integer = 0
Do While rtbCode.Text.ToUpper.IndexOf(oneWord.ToUpper, pos) >= 0
pos = rtbCode.Text.ToUpper.IndexOf(oneWord.ToUpper, pos)
rtbCode.Select(pos, oneWord.Length)
rtbCode.SelectionColor = Color.DarkBlue
pos += 1
Loop
Next
rtbCode.SelectionStart = selectStart
rtbCode.SelectionLength = 0
End Sub
Anyway to improve it so it doesn't flash or anything would be great.
Re: [2008] RichTextbox syntax highlighting
One thing that i'm sure will boost matching keywords is by using regular expression.There are couple of examples if you just google it.I'm sure most of them use regex (regular expression).
Re: [2008] RichTextbox syntax highlighting
Hey mate. :D
There's an example in the Codebank forum that shows how you can do it without flicker. Here's a link :D
Code:
http://www.vbforums.com/showthread.php?t=517116