2

我想以编程方式创建一个表格布局面板。我的代码如下:

        TableLayoutPanel tlpCurrent = new TableLayoutPanel();
        tlpCurrent.RowStyles.Clear();
        tlpCurrent.RowCount++;
        tlpCurrent.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
        tlpCurrent.RowCount++;
        tlpCurrent.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
        tlpCurrent.RowCount++;
        tlpCurrent.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
        tlpCurrent.RowCount++;
        tlpCurrent.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
        tlpCurrent.RowCount++;
        tlpCurrent.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
        tlpCurrent.RowCount++;
        tlpCurrent.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
        tlpCurrent.RowCount++;
        tlpCurrent.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
        tlpCurrent.RowCount++;
        tlpCurrent.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));

        tlpCurrent.ColumnStyles.Clear();
        tlpCurrent.ColumnCount++;
        tlpCurrent.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150f));

        for (int i = 0; i < 3; i++)
        {
            tlpCurrent.ColumnCount++;
            tlpCurrent.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150f));
        }

        tlpCurrent.Location = new Point(500, 100);
        tlpCurrent.Size = new System.Drawing.Size(300, 300);
        tlpCurrent.AutoSize = true;
        this.Controls.Add(tlpCurrent);

但我在 Windows 窗体上看不到它。我确信这段代码运行没有任何错误。有任何想法吗?

4

1 回答 1

3

要使边框可见,您可以使用:

tlpCurrent.CellBorderStyle= TableLayoutPanelCellBorderStyle.Single;
于 2013-10-26T18:07:48.497 回答