Я сделал TableLayoutPanel
(размер: 30 строк и 30 столбцов) с каждой ячейкой, содержащей button
.Однако для генерации TableLayoutPanel
требуется несколько секунд.Есть ли способы сократить это время?Я уже видел функции SuspendLayout()
и ResumeLayout()
, но, похоже, они вообще не увеличивают время генерации.
Любые другие советы по улучшению производительности TableLayoutPanel
?
Вот код для генерации TableLayoutPanel
//LifeField is a derived class of TableLayoutPanel that I created
public LifeField(int x, int y)
{
SetStyle(ControlStyles.DoubleBuffer, true);
RowCount = ROW_COUNT;
ColumnCount = COLUMN_COUNT;
Location = new System.Drawing.Point(x, y);
Anchor = AnchorStyles.None;
Dock = DockStyle.None;
AutoSize = true;
for (int i = 0; i < ColumnCount; i++)
{
this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent));
}
for (int i = 0; i < RowCount; i++)
{
this.RowStyles.Add(new RowStyle(SizeType.Percent));
}
//Fill the TableLayoutPanel with Cell which is a derived class of Button
SuspendLayout();
Visible = false;
for (int i = 0; i < RowCount; i++)
{
for (int j = 0; j < ColumnCount; j++)
{
Cell cell = new Cell();
Controls.Add(cell, j, i);
}
}
Visible = true;
ResumeLayout();
}