8

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?

JYelton
  • 35,664
  • 27
  • 132
  • 191
Gary Willoughby
  • 50,926
  • 41
  • 133
  • 199

3 Answers3

13

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);
David Wengier
  • 10,061
  • 5
  • 39
  • 43
1

some info here:

How to double buffer .NET controls on a form?

Community
  • 1
  • 1
Gulzar Nazim
  • 51,744
  • 26
  • 128
  • 170
-2

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
  • 19,783
  • 6
  • 37
  • 57
  • Your code doesn't compile, the DoubleBuffered property is protected. The op has probably checked the public properties before putting the question. – Szabolcs Antal Jul 27 '17 at 14:46