How to set Size of colum and row of tablelayoutpanel in winform

142 Views Asked by At

I want to create a tablelayoutpanel use C#. This is my codes:

private void create_table()
    {
        table = new TableLayoutPanel();
        table.Size = new Size(500, 500);
        table.RowCount = rows; //10
        table.ColumnCount = cols; //10


        table.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;

        this.table.Location = new System.Drawing.Point(10, 10);

        TableLayoutRowStyleCollection rowStyles = this.table.RowStyles;
        TableLayoutColumnStyleCollection colStyles = this.table.ColumnStyles;

        foreach(RowStyle rowStyle in rowStyles)
        {
            rowStyle.SizeType = SizeType.Percent;
            rowStyle.Height = 10;
        }
        foreach (ColumnStyle colStyle in colStyles)
        {
            colStyle.SizeType = SizeType.Percent;
            colStyle.Width = 10;
        }
        this.Controls.Add(table);
    }

But it doesn't work. Did I miss something? enter image description here

Thanks.

0

There are 0 best solutions below