【问题标题】:TableLayoutPanel slow because of autosize and/or nested TableLayoutPanels?TableLayoutPanel 因自动调整大小和/或嵌套 TableLayoutPanel 而变慢?
【发布时间】:2013-02-18 07:37:04
【问题描述】:
我有一些 TableLayoutPanel,其中第一个“层”有 1 列和 10 行,其中一些行包含 UserControl 或另一个具有 2 或 3 列和一些行的 TableLayoutPanel。其中一两个包含另一个 TableLayoutPanel,但仅此而已。因此,嵌套 TableLayoutPanel 最多有 3 个“级别”。其中大部分都设置为自动调整大小,因为某些 UserControls 可能会改变它们的大小。当包含这样一个嵌套 TableLayoutPanel 的表单时,UserControls “闪烁”,看起来它们加载非常缓慢。
- 我是否使用了过多的自动调整大小?
- 还是我的面板太嵌套了?
【问题讨论】:
标签:
c#
winforms
tablelayoutpanel
【解决方案1】:
我认为闪烁与“自动调整大小”或“嵌套面板”无关。
请参考另一个“S-O”链接:How to avoid flickering in TableLayoutPanel in c#.net
在您添加所有控件之前暂停布局。
TableLayoutPanel panel = new TabelLayoutPanel();
panel.SuspendLayout();
// NOW add controls (including nested-controls) -- do autosizing etc
panel.ResumeLayout();
也看看使用双缓冲。您必须创建TableLayoutPanel 的子类。请参阅example。
希望这会有所帮助。