c# - WinForms - Form.DoubleBuffered 属性会影响放置在该窗体上的控件吗?

标签 c# .net winforms doublebuffered

Form 具有 DoubleBuffered 属性(bool,继承自 Control)。

如果将其设置为 true,是否所有控件都位于窗体上以双缓冲方式放置在绘制到屏幕上的窗体上?或者您是否需要担心自己的 DoubleBuffered 属性?

最佳答案

根据我的内存,不,双缓冲不会转移到子控件。您需要为每个单独设置它。我会用谷歌搜索它,看看我是否能找到一个来源来证明/反驳这一点......

编辑:找到这个:http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic17173.aspx

只是想到了一个快速的 hack 来解决这个问题。基本上,使用反射获取“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);
    }
}

然后,在您的表单代码中,执行如下操作:

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

关于c# - WinForms - Form.DoubleBuffered 属性会影响放置在该窗体上的控件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/911376/

相关文章:

C# WPF - 长时间点击按钮操作

c# - 如何拆分文本框值并将其存储在两个字符串变量中 C#

.net - Silverlight 5 列表框大小调整

c# - 使用 DataSource 属性在 DataGridView 中排序

c# - 如何刷新短时间字符串(C# DateTime.Now)?

winforms - WinForm DateTimePicker 忧郁。那是我吗?

c# - 是这个值对象

c# - 如何在 SpecFlow beforetestrun 和 aftertestrun Hook 之间共享数据?

c# - Webkit 的 .NET 包装器

c# - 使用 BackgroundWorker 进行错误处理