【问题标题】:Reducing flicker when you change images in a panel更改面板中的图像时减少闪烁
【发布时间】:2010-10-23 18:53:04
【问题描述】:

如何减少 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

【问题讨论】:

    标签: vb.net panel flicker


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      SetStyle
      

      在启用标志 OptimisedDoubleBuffering 和 DoubleBuffering 的情况下调用构造函数。

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

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

      【讨论】:

        猜你喜欢
        • 2014-03-19
        • 2015-05-06
        • 1970-01-01
        • 2018-11-26
        • 1970-01-01
        • 2020-08-17
        • 2017-08-24
        • 2011-03-27
        • 2022-09-24
        相关资源
        最近更新 更多