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
  • 34,250
  • 25
  • 123
  • 184
Gary Willoughby
  • 48,529
  • 40
  • 130
  • 197

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
  • 9,875
  • 5
  • 37
  • 43
1

some info here:

How to double buffer .NET controls on a form?

Community
  • 1
  • 1
Gulzar Nazim
  • 51,218
  • 24
  • 126
  • 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,137
  • 6
  • 35
  • 56
  • Your code doesn't compile, the DoubleBuffered property is protected. The op has probably checked the public properties before putting the question. – ChocapicSz Jul 27 '17 at 14:46