I have a custom control that has other controls on it. When the user clicks on it, I recursively go through all controls and change their background color to blue. However, I get a massive flicker problem as the controls change color individually. I have double buffering enabled, but I doubt that it optimizes my drawing. I have a suspicion that this may not be the best way of doing such an effect.
How can I get rid of this flickering? Or is there a better way of doing this?
My call 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();
I found that this solves my problem on Vista and above. WinXP users might be SOL.