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

风流意气都作罢 提交于 2019-11-26 16:55:17

问题


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

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?


回答1:


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

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

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



回答2:


some info here:

How to double buffer .NET controls on a form?




回答3:


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

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


来源:https://stackoverflow.com/questions/220100/how-do-i-enable-double-buffering-of-a-control-using-c-sharp-windows-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!