Enable double buffering without sub classing (Forms)

To enable double buffering on a control without subclassing it, use the method below. Double buffering is disabled in terminal server sessions since it will lower performance instead of increasing it.

public static void setDoubleBuffering(Control control, bool state)
{
   if (!System.Windows.Forms.SystemInformation.TerminalServerSession)
   {
      typeof(Control).InvokeMember("DoubleBuffered",
      System.Reflection.BindingFlags.NonPublic |
      System.Reflection.BindingFlags.Instance  |
      System.Reflection.BindingFlags.SetProperty,
      null,
      control, new object[] { state });
   }
}
Lastest update in September 2017, inital post in September 2017

Write a comment

I appreciate comments, suggestions, compliments etc. Unfortunately I have no time to reply to them. Useful input will be used for sure!