提高TableLayoutPanel的性能-C#

时间:2019-02-20 07:51:17

标签: c# winforms tablelayoutpanel

我制作了一个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();

    }

0 个答案:

没有答案