表格布局面板列/行数 [英] Table layout panel column/row count

查看:38
本文介绍了表格布局面板列/行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 2013,我想创建一个表格布局面板.问题在于行数和列数取决于应用程序读取的文件索引.如果我分别使用RowCount和ColumnCount命令初始化行数和列数,并且最终要创建的数大于我设置的数,会出现错误或异常吗?

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?

推荐答案

您可以在运行时更改数量或行/列.在此示例中,创建了指定数量的行/列.请注意,所有行/列的大小都相同,并且会占据整个 TableLayoutPanel:

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

这篇关于表格布局面板列/行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆