Syntax Highlighter -- RichTextBox
Private Sub rtbHTML_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtbHTML.TextChanged
Dim TextCursor As Long = rtbHTML.SelectionStart
Dim Pos As Long = 1, Quote As Boolean = False, QuotePos As Long = 0, QuoteEnd As Long = 0
While Pos <= Len(rtbHTML.Text)
If Mid(LCase(rtbHTML.Text), Pos, 6) = "<html>" Then
rtbHTML.SelectionStart = Pos - 1
rtbHTML.SelectionLength = 6
rtbHTML.SelectionColor = Color.Blue
ElseIf Mid(LCase(rtbHTML.Text), Pos, 6) = "<head>" Then
rtbHTML.SelectionStart = Pos - 1
rtbHTML.SelectionLength = 6
rtbHTML.SelectionColor = Color.Blue
ElseIf Mid(LCase(rtbHTML.Text), Pos, 6) = "<body>" Then
rtbHTML.SelectionStart = Pos - 1
rtbHTML.SelectionLength = 6
rtbHTML.SelectionColor = Color.Blue
ElseIf Mid(LCase(rtbHTML.Text), Pos, 7) = "</body>" Then
rtbHTML.SelectionStart = Pos - 1
rtbHTML.SelectionLength = 7
rtbHTML.SelectionColor = Color.Blue
ElseIf Mid(LCase(rtbHTML.Text), Pos, 7) = "</head>" Then
rtbHTML.SelectionStart = Pos - 1
rtbHTML.SelectionLength = 7
rtbHTML.SelectionColor = Color.Blue
ElseIf Mid(LCase(rtbHTML.Text), Pos, 7) = "</html>" Then
rtbHTML.SelectionStart = Pos - 1
rtbHTML.SelectionLength = 7
rtbHTML.SelectionColor = Color.Blue
ElseIf Mid(LCase(rtbHTML.Text), Pos, 6) = "<input" Then
rtbHTML.SelectionStart = Pos - 1
rtbHTML.SelectionLength = 6
rtbHTML.SelectionColor = Color.Blue
ElseIf Mid(LCase(rtbHTML.Text), Pos, 8) = "<a href=" Then
rtbHTML.SelectionStart = Pos - 1
rtbHTML.SelectionLength = 8
rtbHTML.SelectionColor = Color.Purple
ElseIf Mid(LCase(rtbHTML.Text), Pos, 4) = "</a>" Then
rtbHTML.SelectionStart = Pos - 1
rtbHTML.SelectionLength = 4
rtbHTML.SelectionColor = Color.Purple
ElseIf Mid(LCase(rtbHTML.Text), Pos, 1) = Chr(CLng("&H" & 22)) Then
If Quote = False Then
Quote = True
QuotePos = Pos - 1
ElseIf Quote = True Then
Quote = False
QuoteEnd = Pos
rtbHTML.SelectionStart = QuotePos
rtbHTML.SelectionLength = QuoteEnd - QuotePos
rtbHTML.SelectionColor = Color.Red
End If
End If
Pos += 1
End While
rtbHTML.SelectionStart = TextCursor
rtbHTML.SelectionLength = 0
rtbHTML.SelectionColor = Color.Black
End Sub
I'm making a HTML code editor. Once I have too many color code strings to parse, it gets really laggy. About 20 colors/lines will make it lag soooo bad. How can I get it to be better and non-laggy?
Other ways of syntax highlighting are gladly accepted...

