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

a 夏天 提交于 2019-12-22 07:55:46

问题


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?


回答1:


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();
        }
    }


来源:https://stackoverflow.com/questions/911376/winforms-does-the-form-doublebuffered-property-influence-controls-placed-on-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!