如何使用C#(Windows窗体)启用控件的双缓冲?
-
03-07-2019 - |
题
如何使用C#(Windows窗体)启用控件的双缓冲?
我有一个面板控件,我正在绘制内容,也是一个所有者绘制的标签控件。两者都有闪烁,所以如何启用双缓冲?
解决方案
在控件的构造函数中,适当地设置DoubleBuffered属性和/或ControlStyle。
例如,我有一个简单的DoubleBufferedPanel,其构造函数如下:
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.ContainerControl |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.SupportsTransparentBackColor
, true);
其他提示
这里有一些信息:
使用继承自System.Windows.Forms.Control的DoubleBuffered属性。
System.Windows.Forms.Form myForm = new System.Windows.forms.Form();
myForm.DoubleBuffered = true;
不隶属于 StackOverflow