启用双缓冲
我已经看到以下代码在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Control.DoubleBuffering
执行,因此您的代码也会设置
ControlStyles.UserPaint
(此时可能没有效果)。Control.DoubleBuffering
performsso your code sets
ControlStyles.UserPaint
as well (which probably has no effect at this point).设置表单的 DoubleBuffering 将为该表单设置双缓冲。 它与调用相同。
其他标志(如 UserPaint 和 AllPaintingInWmPaint)是不能通过简单设置 control.DoubleBuffering = true 来设置的样式
Setting a form's DoubleBuffering will set double buffering for that form. It's the same as calling
The other flags like UserPaint and AllPaintingInWmPaint are styles that aren't set by simply setting control.DoubleBuffering = true
在 .NET 1.x 中,控件上没有
DoubleBuffered
属性,因此SetStyle
是启用它的唯一方法。 您看到的使用SetStyle
的代码可能要么在 1.x 天后仍然存在,要么来自从那时起就没有改变习惯的开发人员。In .NET 1.x, there was no
DoubleBuffered
property on controls, soSetStyle
was the only way to enable it. Code your see that usesSetStyle
is probably either still around from 1.x days, or from developers who just haven't changed their habits since then.来自 Stackoverflow:如何双缓冲 .NET 控件在表格上?:
From Stackoverflow: How to double buffer .NET controls on a form?: