Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax Highlighting..
#1
I don't really know what is it called, but I think its called syntax highlighting. For example if you type "if" it will become blue while the other text stays black... How to do that.
#2
If you use any version of Visual Basic or Visual Studio, it should automatically highlight the syntax.

Maybe you're writing the VBScript program in notepad, if so, well, it will never highlight anything.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#3
Here is a nice control that will handle that for you, if you don't want to program it yourself.

<!-- m --><a class="postlink" href="http://www.freevbcode.com/ShowCode.asp?ID=5176">http://www.freevbcode.com/ShowCode.asp?ID=5176</a><!-- m -->

But if you do want to program it yourself, it should look something like this:

Code:
Public Sub HighlightKeyWords(ByVal rtb As RichTextBox, ByVal words As List(Of String))
        Dim selection_original As Integer = rtb.SelectionStart
        For Each word As String In words
            If (rtb.Text.Contains(word)) Then
                Dim pos As Integer = rtb.Find(word)
                If (pos <> -1) Then
                    'The value was found and now has a position
                    rtb.Select(pos, word.Length)
                    rtb.SelectionColor = Color.Blue
                    'Now go back to our original selection
                    rtb.Select(selection_original, 0)
                End If
            End If
        Next
    End Sub
My Blog | My Setup | My Videos | Have a wonderful day.
#4
Thanks..


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with Syntax Highlighting? brandonio21 2 12,792 04-02-2011, 10:37 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)