Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27368

VS 2010 [RESOLVED] Syntax Highlighting

$
0
0
I'm doing syntax highlighting for an HTML rich text editor. The RTE is working fine except I want syntax highlighting. Here's what I've got so far:
Code:

If e.KeyCode = Keys.Enter Then
            Try
                Dim text As String = RichTextBox1.Lines(RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart))
                Dim keyword As String = text.Substring(0, 5)
                If keyword.StartsWith("<li>") Then
                    RichTextBox1.SelectionStart = RichTextBox1.GetFirstCharIndexOfCurrentLine()
                    RichTextBox1.SelectionStart = RichTextBox1.SelectionStart + text.Length
                    RichTextBox1.SelectedText = vbNewLine & "<li>"
                    e.SuppressKeyPress = True
                End If
            Catch ex As Exception

            End Try
        ElseIf e.KeyCode = Keys.Space Then
            MsgBox(Word)
            With Word
                If ListBox2.Items.Contains(Word) = True Then
                    RichTextBox1.SelectionStart = RichTextBox1.SelectionStart - Word.Length
                    RichTextBox1.SelectionLength = Word.Length
                    RichTextBox1.SelectionColor = Color.Blue
                    RichTextBox1.SelectionStart = RichTextBox1.SelectionStart + Word.Length
                    RichTextBox1.SelectionLength = 0
                    RichTextBox1.SelectionColor = Color.Black
                Else
                    RichTextBox1.SelectionColor = Color.Black
                End If
                Word = String.Empty
            End With
        ElseIf e.KeyCode = 190 Then
            With Word
                Try
                    If ListBox2.Items.Contains(Word) = True Then
                        RichTextBox1.SelectionStart = RichTextBox1.SelectionStart - Word.Length
                        RichTextBox1.SelectionLength = Word.Length
                        RichTextBox1.SelectionColor = Color.Blue
                        RichTextBox1.SelectionStart = RichTextBox1.SelectionStart + Word.Length
                        RichTextBox1.SelectionLength = 0
                        RichTextBox1.SelectionColor = Color.Black
                    Else
                        RichTextBox1.SelectionColor = Color.Black
                    End If
                    Word = String.Empty
                Catch ex As Exception
                    If e.KeyCode = 16 Then
                        Word = String.Empty
                    End If
                End Try
            End With
        Else
            If Asc(Chr(e.KeyCode)) > -1 And Asc(Chr(e.KeyCode)) < 100 Then

                Word = Word & Chr(e.KeyCode).ToString.ToLower
            End If
        End If

This code is still in the making. ANyway, you can see that, if the key is not < (keycode 190) or SPACE it adds the character to a string called WORD. If ListBox2 (the list of keywords) contains WORD, it makes the text color blue. Now that worked fine. But I also wanted to clear WORD when these keys are pressed: <, =, "", and backspace

What I do in the ELSE section is simply try to filter out characters. Obviously, the code is nowhere close to done there, as I am attempting to use ASC, but don't know the keycodes for letters (any help here?). When I type SHIFT + <, the Chr(e.KeyCode) is this little cross sign. I don't want that there...I just want letters.

Here's my question: How can I get ONLY letters, no weird signs, no backspaces, just the letters in the word?

Viewing all articles
Browse latest Browse all 27368

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>