TableLayoutPanel没有显示C#

时间:2013-10-26 17:10:56

标签: c# winforms tablelayoutpanel

我想以编程方式创建一个tablelayoutpanel。我的代码如下:

        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窗体上看到它。我确信这段代码运行没有任何错误。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

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

tlpCurrent.CellBorderStyle= TableLayoutPanelCellBorderStyle.Single;