Results 1 to 3 of 3

Thread: [RESOLVED] [2008] RichTextbox syntax highlighting

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    70

    Resolved [RESOLVED] [2008] RichTextbox syntax highlighting

    I have a richtextbox on my form and currently have made a simple syntax highlighting for it. It works great with a small amount of text but as the text amount increases it starts flashing and locks the textbox while typing.

    This is my current code. I call the sub on the textchanged event.

    Basically what happens is I have a list of words that it checks for and if it finds it, it colors the word.

    Code:
        Sub ColorCode()
                Dim selectStart As Integer = rtbCode.SelectionStart
                rtbCode.Select(0, rtbCode.Text.Length)
                rtbCode.SelectionColor = Color.Black
                rtbCode.DeselectAll()
                For Each oneWord As String In event_list
                    Dim pos As Integer = 0
                    Do While rtbCode.Text.ToUpper.IndexOf(oneWord.ToUpper, pos) >= 0
                        pos = rtbCode.Text.ToUpper.IndexOf(oneWord.ToUpper, pos)
                        rtbCode.Select(pos, oneWord.Length)
                        rtbCode.SelectionColor = Color.DarkBlue
                        pos += 1
                    Loop
                Next
                rtbCode.SelectionStart = selectStart
                rtbCode.SelectionLength = 0
        End Sub
    Anyway to improve it so it doesn't flash or anything would be great.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: [2008] RichTextbox syntax highlighting

    One thing that i'm sure will boost matching keywords is by using regular expression.There are couple of examples if you just google it.I'm sure most of them use regex (regular expression).

  3. #3
    Lively Member
    Join Date
    Oct 2007
    Posts
    118

    Re: [2008] RichTextbox syntax highlighting

    Hey mate.

    There's an example in the Codebank forum that shows how you can do it without flicker. Here's a link

    Code:
    http://www.vbforums.com/showthread.php?t=517116

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width