C# – WinForms – Does the Form.DoubleBuffered property influence controls placed on that form

cdoublebufferednetwinforms

Form has the DoubleBuffered property (bool, inherited from Control).

If this is set to true, are all controls placed on the form drawn to screen in a double buffered fashion by virtue of being on the Form? Or do you need to worry about their own DoubleBuffered properties?

Best Answer

From what I remember, no, double buffering does NOT carry over to child controls. You need to set it for each one individually. I'll google it and see if I can find a source to prove / disprove this...

EDIT: Found this: http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic17173.aspx

Just thought of a quick hack to get around this. Basically, use reflection to get the "DoubleBuffered" property, and then set it:

public static class Extensions
{
    public static void EnableDoubleBuferring(this Control control)
    {
        var property = typeof(Control).GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
        property.SetValue(control, true, null);
    }
}

Then, in your form code, do something like this:

    public Form1()
    {
        InitializeComponent();
        this.DoubleBuffered = true;
        foreach (Control control in this.Controls)
        {
            control.EnableDoubleBuferring();
        }
    }