启用双缓冲

发布于 2024-07-08 11:29:16 字数 321 浏览 9 评论 0原文

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

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

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

I've seen the following code to enable double buffering on a winform:

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

Is this different in any way from simply setting Form.DoubleBuffering = true?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜心 2024-07-15 11:29:16

Control.DoubleBuffering 执行

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

,因此您的代码也会设置 ControlStyles.UserPaint (此时可能没有效果)。

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

苏佲洛 2024-07-15 11:29:16

设置表单的 DoubleBuffering 将为该表单设置双缓冲。 它与调用相同。

form.SetStyle(ControlStyles.OptimizedDoubleBuffer, value);

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

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

像你 2024-07-15 11:29:16

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

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.

命比纸薄 2024-07-15 11:29:16

来自 Stackoverflow:如何双缓冲 .NET 控件在表格上?

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

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); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文