Question

How do I reduce flicker in a vb2005 panel? Inside the parent panel I have 2 other panels that I'm am using.

The outer most panel contains a background sprite and the two innermost panels are overlays that change to fit the places in the background sprite.

When I change the overlay sprites I would like to reduce the flicker and make it a smooth transition from one sprite to the next.

Here is the code that changes the images in the overlay panels the overlay panel is not changed if the new value is the same as the old value

 Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll, TrackBar1.Scroll
    If (Panel2.Tag <> TrackBar1.Value) Then
        Panel2.Tag = TrackBar1.Value
        Panel2.BackgroundImage = tops(TrackBar1.Value) //img array for the top panel
        Panel2.Update()
    End If
    If (Panel3.Tag <> TrackBar2.Value) Then
        Panel3.Tag = TrackBar2.Value
        If (TrackBar2.Value > 0) Then
            Panel3.Location = New Point(182, 210)
        Else
            Panel3.Location = New Point(182, 209)
        End If
        Panel3.BackgroundImage = bottoms(TrackBar2.Value)//img array for the bottom panel
        Panel3.Update()
    End If
Was it helpful?

Solution

You're not going to like this answer. The flicker is caused by the fact that the default .NET panel is not double buffered - so it does all the drawing directly in the visible memory, not a back buffer.

You need to subclass the Panel class and enable double buffering on the new class. This can be done by doing a

SetStyle

call in the constructor with the flags OptimisedDoubleBuffering and DoubleBuffering enabled.

Once you have the new panel class that is double buffered, you can use them in your application instead of the standard Panel.

I told you you wouldn't like the answer ;)

OTHER TIPS

Rein is right, subclassing is the best way. In the meantime though, change that call from Update to Invalidate; that might help a little.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top