=begin
something like this
if it can be done ?
=end
heres what i have so far.
Public Class ScriptEditor
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
Dim words As New List(Of String)
words.Add("Select")
words.Add("Insert")
Dim arrKeyWords() As String, strKW As String
Dim arrOperators() As String, strOP As String
Dim arrComments() As String, strCM As String
Dim arrVariables() As String, strVAR As String
arrKeyWords = New String() {"alias", "and", "begin", "break", "case", "catch", "class", "def", "do", "elsif", "else", "fail" _
, "ensure", "for", "end", "if", "in", "module", "next", "not", "or", "raise" _
, "redo", "rescue", "retry", "return", "then", "throw", "super", "unless", "undef", "until" _
, "when", "while", "yield", "BEGIN", "END", "Defined?", "nil", "self", "True", "False" _
, "__FILE__", "__LINE__"}
arrOperators = New String() {"=", "==", "+", "-", "*", "/", ">", "<", "||", ":"}
arrComments = New String() {"=begin", "=end", "#"}
arrVariables = New String() {"@", "@@", "$"}
If RichTextBox1.Text.Length > 0 Then
Dim selectStart As Integer = RichTextBox1.Selectionstart
RichTextBox1.Select(0, RichTextBox1.Text.Length)
RichTextBox1.SelectionColor = Color.Black
RichTextBox1.DeselectAll()
'Variable Colouring
For Each strVAR In arrVariables
Dim pos As Integer = 0
Do While RichTextBox1.Text.ToUpper.IndexOf(strVAR.ToUpper, pos) >= 0
pos = RichTextBox1.Text.ToUpper.IndexOf(strVAR.ToUpper, pos)
RichTextBox1.Select(pos, strVAR.Length)
RichTextBox1.SelectionColor = Color.Blue
pos += 1
Loop
Next
'Keyword Colouring
For Each strKW In arrKeyWords
Dim pos As Integer = 0
Do While RichTextBox1.Text.ToUpper.IndexOf(strKW.ToUpper, pos) >= 0
pos = RichTextBox1.Text.ToUpper.IndexOf(strKW.ToUpper, pos)
RichTextBox1.Select(pos, strKW.Length)
RichTextBox1.SelectionColor = Color.Blue
pos += 1
Loop
Next
' Operator Colouring
For Each strOP In arrOperators
Dim pos As Integer = 0
Do While RichTextBox1.Text.ToUpper.IndexOf(strOP.ToUpper, pos) >= 0
pos = RichTextBox1.Text.ToUpper.IndexOf(strOP.ToUpper, pos)
RichTextBox1.Select(pos, strOP.Length)
RichTextBox1.SelectionColor = Color.LightBlue
pos += 1
Loop
Next
' Comment Colouring
For Each strCM In arrComments
Dim pos As Integer = 0
Do While RichTextBox1.Text.ToUpper.IndexOf(strCM.ToUpper, pos) >= 0
pos = RichTextBox1.Text.ToUpper.IndexOf(strCM.ToUpper, pos)
RichTextBox1.Select(pos, strCM.Length)
RichTextBox1.SelectionColor = Color.Green
pos += 1
Loop
Next
RichTextBox1.Selectionstart = selectStart
End If
End Sub
End Class

New Topic/Question
Reply




MultiQuote






|