简体   繁体   English

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

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

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? 两者都有闪烁,所以如何启用双缓冲?

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

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM