2011-10-09 43 views
0

我有一個自定義控件,其上有其他控件。當用戶點擊它時,我遞歸地遍歷所有控件並將其背景顏色更改爲藍色。但是,當控件單獨更改顏色時,我會遇到大量閃爍問題。我啓用了雙緩衝,但我懷疑它優化了我的繪圖。我懷疑這可能不是做這種效果的最佳方式。更改背景時自定義控件閃爍

我該如何擺脫這種閃爍?或者有更好的方法來做到這一點?

我的電話的onclick:

ControlUtils.SetColorRecursive(this, Color.LightSteelBlue); 

SetColorRecursive:

tCtl.SuspendLayout(); 

     if (tCtl != null) 
     { 
      // Set Color 
      tCtl.BackColor = tColor; 

      foreach (Control tSubCtl in tCtl.Controls) 
      { 
       // Ignore the following 
       if (tSubCtl is TextBox) continue; 
       if (tSubCtl is ListBox) continue; 
       if (tSubCtl is NumericUpDown) continue; 

       // Recursively change sub-controls 
       SetColorRecursive(tSubCtl, tColor); 
      } 
     } 

    tCtl.ResumeLayout(); 
+0

谷歌搜索產生的結果提到了一種稱爲合成的不同類型的雙緩衝。任何人都知道這種方法? – MarkP

回答

0

我發現這解決了我在Vista和以上的問題。 WinXP用戶可能是SOL。

protected override CreateParams CreateParams 
    { 
     get 
     { 
      // This eliminates child control flicker when selecting 
      CreateParams cp = base.CreateParams; 
      cp.ExStyle |= 0x02000000; 
      return cp; 
     } 
    } 
+0

XP是支持樣式的Windows的第一個版本。 –

0

你對每一個控制的背景下啓用雙緩衝被重新着色? ( - 不只是表格)

+0

的確,我確實。我找到了解決方案。 – MarkP