如何使用 C#(Windows 窗体)启用控件的双缓冲?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/220100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 18:40:03  来源:igfitidea点击:

How do I enable double-buffering of a control using C# (Windows forms)?

c#.netwinformsdoublebufferedownerdrawn

提问by Gary Willoughby

How do I enable double-buffering of a control using C# (Windows forms)?

如何使用 C#(Windows 窗体)启用控件的双缓冲?

I have a panel control which I am drawing stuff into and also an owner-drawn tab control. Both suffer from flicker, so how can I enable double-buffering?

我有一个面板控件,我正在将内容绘制到其中,还有一个所有者绘制的选项卡控件。两者都受到闪烁的影响,那么如何启用双缓冲?

采纳答案by David Wengier

In the constructor of your control, set the DoubleBuffered property, and/or ControlStyle appropriately.

在控件的构造函数中,适当地设置 DoubleBuffered 属性和/或 ControlStyle。

For example, I have a simple DoubleBufferedPanel whose constructor is the following:

例如,我有一个简单的 DoubleBufferedPanel,其构造函数如下:

this.DoubleBuffered = true;
this.SetStyle(ControlStyles.UserPaint | 
              ControlStyles.AllPaintingInWmPaint |
              ControlStyles.ResizeRedraw |
              ControlStyles.ContainerControl |
              ControlStyles.OptimizedDoubleBuffer |
              ControlStyles.SupportsTransparentBackColor
              , true);

回答by Gulzar Nazim

回答by Mats Fredriksson

Use the DoubleBuffered property, inherited from the System.Windows.Forms.Control.

使用从 System.Windows.Forms.Control 继承的 DoubleBuffered 属性。

System.Windows.Forms.Form myForm = new System.Windows.forms.Form();
myForm.DoubleBuffered = true;