How can I set the protected DoubleBuffered
property of the controls on a form that are suffering from flicker?
Extension method to turn double buffering on or off for controls
public static class ControlExtentions
{
///
/// Turn on or off control double buffering (Dirty hack!)
///
/// Control to operate
/// true to turn on double buffering
public static void MakeDoubleBuffered(this Control control, bool setting)
{
Type controlType = control.GetType();
PropertyInfo pi = controlType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(control, setting, null);
}
}
Usage (for example how to make DataGridView DoubleBuffered):
DataGridView _grid = new DataGridView();
// ...
_grid.MakeDoubleBuffered(true);