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

狂风中的少年 提交于 2019-12-05 10:18:26

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