C#:如何为多维数组动态创建控件

C#:如何为多维数组动态创建控件,c#,winforms,C#,Winforms,当我在标签中写入一个数字并按下按钮时,它必须显示一个动态分配:第一列是数字当前,然后是带有组合框的4列。所以,当我按3时,它可能会显示3行,带有数字和组合框等等。我如何分配?使用多维数组和对象列表时,您需要在表单中添加一个FlowLayoutPanel,然后按如下方式添加行: private void AddRow() { //First create and setup your controls that are supposed to be in a row: ComboB

当我在标签中写入一个数字并按下按钮时,它必须显示一个动态分配:第一列是数字当前,然后是带有组合框的4列。所以,当我按3时,它可能会显示3行,带有数字和组合框等等。我如何分配?使用多维数组和对象列表

时,您需要在
表单
中添加一个
FlowLayoutPanel
,然后按如下方式添加行:

private void AddRow()
{
    //First create and setup your controls that are supposed to be in a row:
    ComboBox cb1 = new ComboBox(){ /* settings */ };
    // Other Controls


    //Then add them to the FlowLayoutPanel:
    flowLayoutPanel1.Controls.Add(cb1);
    // add other controls

    // Then set a line break at the end of row:
    flowLayoutPanel1.SetFlowBreak(cb4, true); // let's say cb4 is the last control of the row.

}
然后您可以使用如下方法:

int numRows;
bool success = int.TryParse(textBox1.text, out numRows); // lets say textBox1 contains number of rows.
if(success)
{
    for(int i = 0; i < numRows; i++)
    {
        AddRow();
    }
}
int numRows;
bool success=int.TryParse(textBox1.text,out numRows);//假设textBox1包含行数。
如果(成功)
{
对于(int i=0;i
您可以指定您使用的框架吗?Windows窗体?WPF?ASP.NET?我正在使用windows窗体。您尝试了什么。我们不是代码提供程序..欢迎使用stack请阅读然后编辑您的问题,并向我们展示您尝试过的内容,并描述当前解决方案中存在的任何问题您是否希望在运行时根据输入向表单添加控件?