【问题标题】:Enabling Double Buffering启用双缓冲
【发布时间】:2008-11-19 17:01:58
【问题描述】:

我已经看到以下代码在 winform 上启用双缓冲:

// Activates double buffering 
this.SetStyle(ControlStyles.DoubleBuffer |
   ControlStyles.OptimizedDoubleBuffer |
   ControlStyles.UserPaint |
   ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();

这与简单地设置 Form.DoubleBuffering = true 有什么不同吗?

【问题讨论】:

    标签: winforms visual-studio-2008 doublebuffered


    【解决方案1】:

    Control.DoubleBuffering 执行

    SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, value);
    

    因此您的代码也设置了ControlStyles.UserPaint(此时可能无效)。

    【讨论】:

      【解决方案2】:

      设置表单的 DoubleBuffering 将为该表单设置双缓冲。和调用是一样的

      form.SetStyle(ControlStyles.OptimizedDoubleBuffer, value);
      

      UserPaint 和 AllPaintingInWmPaint 等其他标志是不能通过简单地设置 control.DoubleBuffering = true 来设置的样式

      【讨论】:

        【解决方案3】:

        在 .NET 1.x 中,控件上没有 DoubleBuffered 属性,因此 SetStyle 是启用它的唯一方法。使用SetStyle 的代码可能在 1.x 天左右仍然存在,或者来自从那时起就没有改变习惯的开发人员。

        【讨论】:

          【解决方案4】:

          来自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); 
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2013-08-14
            • 2011-03-05
            • 2011-08-20
            • 2011-04-23
            • 2011-10-16
            • 2012-01-19
            • 2011-04-12
            相关资源
            最近更新 更多