2009-05-04 63 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

賴是正確的,子類是最好的方式。同時,將該調用從更新更改爲無效;這可能會有所幫助。