VB.NET Syntax Coding
- by Yiu Korochko
I know many people ask how some of these are done, but I do not understand the context in which to use the answers, so...
I'm building a code editor for a subversion of Python language, and I found a very decent way of highlighting keywords in the RichTextBox through this:
bluwords.Add(KEYWORDS GO HERE)
If scriptt.Text.Length > 0 Then
Dim selectStart2 As Integer = scriptt.SelectionStart
scriptt.Select(0, scriptt.Text.Length)
scriptt.SelectionColor = Color.Black
scriptt.DeselectAll()
For Each oneWord As String In bluwords
Dim pos As Integer = 0
Do While scriptt.Text.ToUpper.IndexOf(oneWord.ToUpper, pos) >= 0
pos = scriptt.Text.ToUpper.IndexOf(oneWord.ToUpper, pos)
scriptt.Select(pos, oneWord.Length)
scriptt.SelectionColor = Color.Blue
pos += 1
Loop
Next
scriptt.SelectionStart = selectStart2
End If
(scriptt is the richtextbox)
But when any decent amount of code is typed (or loaded via OpenFileDialog) chunks of the code go missing, the syntax selection falls apart, and it just plain ruins it.
I'm looking for a more efficient way of doing this, maybe something more like visual studio itself...because there is NO NEED to highlight all text, set it black, then redo all of the syntaxing, and the text begins to over-right if you go back to insert characters between text.
Also, in this version of Python, hash (#) is used for comments on comment only lines and double hash (##) is used for comments on the same line.
Now I saw that someone had asked about this exact thing, and the working answer to select to the end of the line was something like: ^\'[^\r\n]+$|''[^\r\n]+$
which I cannot seem to get into practice.
I also wanted to select text between quotes and turn it turquoise, such as between the first quotation mark and the second, the text is turquoise, and the same between the 3rd and 4th etcetera...
Any help is appreciated!