如何减少vb2005面板中的闪烁? 在父面板内部,我有两个我正在使用的面板。

最外面的面板包含一个背景精灵,两个最里面的面板是叠加层,它们会更改以适合背景精灵中的位置。

当我更改叠加精灵时,我想减少闪烁并使其从一个精灵到下一个精灵的平滑过渡。

以下是更改覆盖面板中图像的代码 如果新值与旧值

相同,则不会更改覆盖面板
 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
有帮助吗?

解决方案

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

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

来完成
SetStyle

在构造函数中调用OptimisedDoubleBuffering和DoubleBuffering标志。

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

我告诉过你,你不喜欢这个答案;)

其他提示

Rein是对的,子类化是最好的方法。在此期间,将该调用从Update更改为Invalidate;这可能会有所帮助。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top