C# – How to double buffer .NET controls on a form


How can I set the protected DoubleBuffered property of the controls on a form that are suffering from flicker?

Best Solution

Here's a more generic version of Dummy's solution.

We can use reflection to get at the protected DoubleBuffered property, and then it can be set to true.

Note: You should pay your developer taxes and not use double-buffering if the user is running in a terminal services session (e.g. Remote Desktop) This helper method will not turn on double buffering if the person is running in remote desktop.

public static void SetDoubleBuffered(System.Windows.Forms.Control c)
   //Taxes: Remote Desktop Connection and painting
   if (System.Windows.Forms.SystemInformation.TerminalServerSession)

   System.Reflection.PropertyInfo aProp = 
               System.Reflection.BindingFlags.NonPublic | 

   aProp.SetValue(c, true, null);