Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 293
Gary Willoughby Avatar asked Oct 20 '08 21:10

Gary Willoughby


2 Answers

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);
like image 160
David Wengier Avatar answered Sep 19 '22 00:09

David Wengier


some info here:

How to double buffer .NET controls on a form?

like image 45
Gulzar Nazim Avatar answered Sep 18 '22 00:09

Gulzar Nazim