I\'ve seen the following code to enable double buffering on a winform:
// Activates double buffering
this.SetStyle(ControlStyles.DoubleBuffer |
ControlSt
From Stackoverflow: How to double buffer .NET controls on a form?:
public static void SetDoubleBuffered(System.Windows.Forms.Control c)
{
//Taxes: Remote Desktop Connection and painting
//http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx
if (System.Windows.Forms.SystemInformation.TerminalServerSession)
return;
System.Reflection.PropertyInfo aProp = typeof(System.Windows.Forms.Control).GetProperty(
"DoubleBuffered",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
aProp.SetValue(c, true, null);
}
Setting a form's DoubleBuffering will set double buffering for that form. It's the same as calling
form.SetStyle(ControlStyles.OptimizedDoubleBuffer, value);
The other flags like UserPaint and AllPaintingInWmPaint are styles that aren't set by simply setting control.DoubleBuffering = true
In .NET 1.x, there was no DoubleBuffered
property on controls, so SetStyle
was the only way to enable it. Code your see that uses SetStyle
is probably either still around from 1.x days, or from developers who just haven't changed their habits since then.
Control.DoubleBuffering
performs
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, value);
so your code sets ControlStyles.UserPaint
as well (which probably has no effect at this point).