Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

c# - Table layout panel column/row count

I'm working on visual studio 2013 and i want to create a table layout panel. The problem is that the number of rows and columns depend on the index of a file the application reads. If i use the commands RowCount and ColumnCount to initialise the number of rows and columns respectively, and the final number i want to create is bigger than that i set, there will be any error or exception?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...