WinForms - Form.DoubleBuffered属性是否会影响该窗体上的控件?

时间:2022-02-10 15:01:56

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

Form具有DoubleBuffered属性(bool,继承自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?

如果设置为true,那么由于在表单上,​​是否所有控件都以双缓冲方式放置在屏幕上?或者您是否需要担心自己的DoubleBuffered属性?

1 个解决方案

#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

编辑:发现这个: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:

想到快速破解这个问题。基本上,使用反射来获取“DoubleBuffered”属性,然后设置它:

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

#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

编辑:发现这个: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:

想到快速破解这个问题。基本上,使用反射来获取“DoubleBuffered”属性,然后设置它:

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