净TableLayoutPanel中 - 清除控制很慢 [英] .Net TableLayoutPanel – Clearing Controls is Very Slow

查看:291
本文介绍了净TableLayoutPanel中 - 清除控制很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是非常简单的。

我有一个填充基础数据库查询控件(只是标签,按钮和一些面板的按钮)一个TableLayoutPanel。当数据需要被刷新,我使用TableLayoutPanel.Controls.Clear()。不幸的是,这是一个非常缓慢的操作。我希望它为比code填充表快,但它至少是3或4倍慢

I have a TableLayoutPanel that is populated with controls (just Labels, Buttons, and some Panels with buttons) based on a database query. When the data needs to be refreshed, I use TableLayoutPanel.Controls.Clear(). Unfortunately, this is a very slow operation. I would expect it to be faster than the code populating the table, but it is at least 3 or 4 times slower.

予明确证明,执行Controls.Clear()时通过执行该作为消息框后做给TableLayoutPanel中的单一的东西被显示(然后该程序返回)是缓慢的。该控制明显消失,从下往上。当记录用于重新填充TableLayoutPanel中,从上到下出现在控制的速度几乎速度比我能看到的。

I definitively proved that the slowness is when executing Controls.Clear() by executing this as the single thing done to the TableLayoutPanel after a message box is displayed (then the procedure returns). The controls visibly disappear from the bottom up. When the recordset is used to repopulate the TableLayoutPanel, the speed of the controls appearing from top to bottom is almost faster than I can see.

我已经在做TableLayoutPanel.SuspendLayout()和ResumeLayout()。

I'm already doing TableLayoutPanel.SuspendLayout() and ResumeLayout().

使用 this.DoubleBuffered = TRUE 的形式似乎没有做任何事情。

Using this.DoubleBuffered = true on the form doesn't appear to do anything.

我可以处置的整个控制,并通过code重新创建它,但是这是一个很大的痛苦,使有一个漂亮的窗体设计的GUI毫无意义。我会钻进去,我就控制设置每个属性,并创建一个行code吧(虽然我想我可以得到这个出了设计$ C $的C本身,它仍然感觉错了)。

I could just Dispose the entire control and recreate it through code, but this is a big pain and makes having a nice form designer GUI pointless. I would have to dig into every property I've set on the control and create a line of code for it (though I guess I could get this out of the designer code itself, it still feels wrong).

这是怎么做的工作更快任何想法?我甚至使用其他方法,除了一个TableLayoutPanel开......我只是需要自由地把多个按钮每个小区或限制,为了能够跨越在表头列。

Any ideas on how to do the job faster? I'm even open to using other methods besides a TableLayoutPanel... I just need the freedom to put multiple buttons per cell or barring that to be able to span columns in the table header.

CAN C#至少冻结整个窗体,而它重绘后再搽一次全部?

Can C# at least freeze the whole form while it redraws and then paint all at once?

推荐答案

我碰到的问题用缓慢TableLayoutPanels为好。而不是设置DoubleBuffered财产的形式,我已经找到了最好的解决方案是创建一个新的类继承自TableLayoutPanel中,并且在类的构造函数,使双缓冲:

I've run into issues with slowness using TableLayoutPanels as well. Rather than setting the DoubleBuffered property on the form, the best solution I have found is to create a new class that inherits from TableLayoutPanel, and in that class' constructor, enable double-buffering:

public class DoubleBufferedTableLayoutPanel : TableLayoutPanel
{
    public DoubleBufferedTableLayoutPanel()
    {
        DoubleBuffered = true;
    }
}

然后,使用DoubleBufferedTableLayoutPanel无论你通常会使用一个TableLayoutPanel。

Then, use the DoubleBufferedTableLayoutPanel wherever you would normally use a TableLayoutPanel.

这篇关于净TableLayoutPanel中 - 清除控制很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆