Question

I want to create a tablelayoutpanel programmatically. I have code as follows:

        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);

But I cannot see it on windows form. I am sure this code runs without any error. Any ideas?

Was it helpful?

Solution

To make the borders visible, you can use:

tlpCurrent.CellBorderStyle= TableLayoutPanelCellBorderStyle.Single;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top