Quantcast
Channel: Technical Blog
Viewing all articles
Browse latest Browse all 25

Reduce flickering from controls in C#.Net

$
0
0
Flickering effect can be reduced by double buffering the controls. The below code will help you in reducing the flickering effect from any type of control.

public static class ControlExtensions
    {
        public static void SetDoubleBuffered(System.Windows.Forms.Control c)
        {
            if (System.Windows.Forms.SystemInformation.TerminalServerSession)
                return;

            System.Reflection.PropertyInfo aProp =
                  typeof(System.Windows.Forms.Control).GetProperty(
                        "DoubleBuffered",
                        System.Reflection.BindingFlags.NonPublic |
                        System.Reflection.BindingFlags.Instance);

            aProp.SetValue(c, true, null);
        }
    }

Whether it is a panel, or a Tab control, you can call the above defined function:

ControlExtensions.SetDoubleBuffered(MenuPanel);
ControlExtensions.SetDoubleBuffered(settingsTabControl);


Viewing all articles
Browse latest Browse all 25

Trending Articles