Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms - Does the Form.DoubleBuffered property influence controls placed on that form?

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?

like image 693
xyz Avatar asked May 26 '09 15:05

xyz


People also ask

Which property of a control is used to reduce flickering when it is drawn?

Buffered graphics can reduce or eliminate flicker that is caused by progressive redrawing of parts of a displayed surface.

What is Doublebuffered C#?

Double buffering uses a memory buffer to address the flicker problems associated with multiple paint operations. When double buffering is enabled, all paint operations are first rendered to a memory buffer instead of the drawing surface on the screen.


1 Answers

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();
        }
    }
like image 182
BFree Avatar answered Sep 21 '22 16:09

BFree