views:

2519

answers:

3

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

I have a panelcontrol which i am drawing stuff into and also an owner drawn tabcontrol. Both suffer from flicker, so how to enable double-buffering?

+2  A: 

some info here:

How to double buffer .NET controls on a form?

Gulzar
+2  A: 

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);
Ch00k
simply doing the this.DoubleBuffered = true; is generally enough, good answer though :)
Tom Anderson
A: 

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

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