VB.net Richtextbox flickering

  • Thread starter LifeWater
  • 4 comments
  • 3,364 views
I'm creating a small maki script editor with color coding, and for some reason the richtextbox flickers. I have been reading on the internet that I should be using TX Classes to group actions and preform them on .net, Yet I've no idea what TX classes are....

Previous solutions were to use the LockWindowUpdate API, but this also didn't work, infact I can't even get that API to work properly on VB.net because the handle returned is a pointer and not an integer.... but I didn't play with it much though. Heres my code:

Code:
    Private Sub richtxt_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles richtxt.KeyUp

        Dim i As Integer

        For i = 0 To 10 Step 1
            If (richtxt.Find(Keys(i).Value) = -1) Then
                richtxt.SelectionColor = System.Drawing.Color.Black
            Else

                richtxt.SelectionStart = richtxt.Find(Keys(i).Value)
                richtxt.SelectionLength = Len(Keys(i).Value)
                richtxt.SelectionColor = System.Drawing.Color.Blue

                richtxt.SelectionStart = Len(richtxt.Text)
                richtxt.SelectionLength = 0
                richtxt.SelectionColor = System.Drawing.Color.Black
            End If
        Next
    End Sub

I understand this code is rather simple and inefficient because you could do less loops going line by line doing a type of split(text, " "), but right now I want to try and get the flicker out using this bogged down code, because the other three methods I also know of have caused flickering as well. Anyone have a method they use to stop flickering in rich text boxes?
 
Lemme change the question, anyone know how to use double buffering in general on a richtextbox? I'm not famiilar with this process and theres not much info on it online. I was thinking something along the lines of creating an internal bitmap thats a complete copy of whats visible on the RTB then changing the paint methods to paint the complete screenshots, rather then on the fly text.
 
I'm not sure what you're trying to do here? Could you post a bit more, including the Keys array/type?

I generally steer clear of the rich text box and use the DHTMLEdit control instead. That's like a complete editeable internet explorer window and gives you a lot more to work with.

If you intend to highlight certain words, this is generally done by one simple check when a space or something similar is typed, after which the preceding string is checked and highlighted. That saves some testing and updating. In general, everything that uses a selection is slow. A range or something similar works better, and the DHTMLEdit control of course has the whole HTML object model with asynchronous modifications that never really cause any flicker.
 
Oh sorry I was unclear. I'm creating a maki script editor, and its going to have a color coded syntax similar to what you'd find in php editors, or VB.net and what not. I don't have code anymore, just the outdated stuff I was using. Before I even try to make the syntax color coding, I wanted to stop the flickering. The way it works is after you type something it checks to see if its a keyword, which i store in an array... If they match it selects it, colors it, and moves on down the textbox. This causes flickering. Im just trying to learn how to use double buffering to stop the flickering, because I can't relaease something like that without getting the flickering out. You think your control would be better for what im trying to do?
 
Back