You can change the number or rows/columns at run-time. In this example the specified number of rows/columns are created. Note that all rows/columns will be of equal size and will take up the entire TableLayoutPanel:
private void button1_Click(object sender, EventArgs e)
{
// figure these out from your file:
int rows = 8;
int cols = 5;
// setup the TableLayoutPanel:
InitTableLayoutPanel(tableLayoutPanel1, rows, cols);
}
private void InitTableLayoutPanel(TableLayoutPanel TLP, int rows, int cols)
{
TLP.RowCount = rows;
TLP.RowStyles.Clear();
for (int i = 1; i <= rows; i++)
{
TLP.RowStyles.Add(new RowStyle(SizeType.Percent, 1));
}
TLP.ColumnCount = cols;
TLP.ColumnStyles.Clear();
for (int i = 1; i <= cols; i++)
{
TLP.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 1));
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…