2009-05-04 67 views
1

如何减少vb2005面板中的闪烁? 在父面板内部,我有2个其他面板,我正在使用。当您更改面板中的图像时减少闪烁

最外面的面板包含一个背景精灵,两个最内面的面板是覆盖层,可以更改为适合背景精灵中的位置。

当我改变覆盖精灵时,我想减少闪烁并使其从一个精灵平滑过渡到下一个精灵。

下面是改变 覆盖面板没有改变的覆盖面板上的图像的代码,如果新的值是一样的旧值

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 

回答

3

你不会喜欢这个答案。闪烁是由于默认的.NET面板不是双缓冲 - 所以它直接在可见内存中执行所有绘图,而不是后台缓冲区。

您需要继承Panel类并在新类上启用双缓冲。这可以通过做一个

SetStyle 

调用的标志OptimisedDoubleBuffering和DoubleBuffering启用的构造函数。

一旦您拥有双缓冲的新面板类,您可以在应用程序中使用它们而不是标准面板。

我告诉你,你不喜欢的答案;)

+0

有趣的方法 – Jim 2009-05-05 00:34:11

0

赖是正确的,子类是最好的方式。同时,将该调用从更新更改为无效;这可能会有所帮助。