Enabling Double Buffering

社会主义新天地 提交于 2019-11-29 16:45:29

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).

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.

Ian Boyd

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); 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!