Reducing flicker when changing panel images

How to reduce flickering on vb2005 panel? Inside the parent panel, I have two more panels that I use.

The outer panel contains the background sprite, and the two innermost panels are overlays that change to match the locations of the background sprite.

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

Here is the code that changes the images in the overlap bars the overlap bar does not change 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

      

+1


source to share


2 answers


You won't like this answer. The flickering is caused by the fact that the .NET pane is not double buffered by default - so it makes the entire drawing directly in visible memory and not back.

You need to subclass the Panel class and enable double buffering in the new class. This can be done by running

SetStyle

      



a constructor call with the OptimizedDoubleBuffering and DoubleBuffering flags enabled.

Once you have a new double buffered pane class, you can use them in your application rather than the standard pane.

I told you that you won't like the answer;)

+3


source


Raine is right, subclassing is the best way. However, change this call from "Update to invalidate"; which might help a little.



0


source







All Articles