2 qq 39450261 qq_39450261 于 2017.08.31 15:48 提问

输入需要的控件数,每行五列,多的控件在第二行排列

public class InfoClass
{

    public string InfoName { get; set; }  //页面名字
    public string ConType { get; set; }//控件类型
    public string ConValue { get; set; }//控件的默认值
    public int ConIndex { get; set; }//控件的索引
    public string ConDesc { get; set; }//控件描述
    public string CFName { get; set; }//控件名称
}

public partial class Contrl : Form
{
private InfoClass ic;

    public Contrl(InfoClass ic)
    {
        InitializeComponent();
        this.ic = ic;
    }

    int x = 0;
    int y = 0;

    private void Contrl_Load(object sender, EventArgs e)
    {
        this.Name = ic.InfoName;
        this.Text = ic.InfoName;
            //列
            for (int i = 0; i < ic.ConIndex; i++)
            {
                //行
                for (int j = 0; j <ic.ConIndex; j++)
                {
                    Label lb = new Label();
                    lb.Visible = true;
                    lb.Text = ic.ConValue;
                    lb.Width = 50;
                    lb.Location = new Point(20 + (lb.Width + 100) * i, 40 + 30 * j);
                    panel1.Controls.Add(lb);

                    TextBox tb = new TextBox();
                    tb.Visible = true;
                    tb.Text = ic.ConValue;
                    tb.Name = ic.CFName;
                    tb.Width = 100;
                    tb.Location = new Point(20 + lb.Width + (lb.Width + 100) * i, 40 + 30 * j);
                    panel1.Controls.Add(tb);
                }
            }
        }


![图片说明](http://img.ask.csdn.net/upload/201708/31/1504165670_376855.png)

我只能这样排列,请大家帮帮忙!!
Csdn user default icon
上传中...
上传图片
插入图片