BP Forums
Syntax Highlighting.. - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9)
+----- Thread: Syntax Highlighting.. (/showthread.php?tid=546)



Syntax Highlighting.. - Fuzzy168 - 06-16-2012

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.


Re: Syntax Highlighting.. - Vinwarez - 06-18-2012

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.


Re: Syntax Highlighting.. - brandonio21 - 06-18-2012

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



Re: Syntax Highlighting.. - Fuzzy168 - 06-18-2012

Thanks..