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

Gary Willoughby picture Gary Willoughby · Oct 20, 2008 · Viewed 27.1k times · Source

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?

Answer

David Wengier picture David Wengier · Oct 21, 2008

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