Add label to Panel programmatically

后端 未结 2 844
误落风尘
误落风尘 2021-01-13 16:25

So I have a form, and I want to add some Panels with some controls(labels, and radiobuttons) when the form loads.
And I want to do it from the code, of course(it\'s for

2条回答
  •  -上瘾入骨i
    2021-01-13 16:35

    Add the panel just created to the Form.Controls collection

    private void VizualizareTest_Load(object sender, EventArgs e)
    {
        for (int i = 0; i < 4; i++)
        {
            Panel pan = new Panel();
            pan.Name = "panel" + i;
            ls.Add(pan);
            Label l = new Label();
            l.Text = "l"+i;
            pan.Location = new Point(10, i * 100);
            pan.Size = new Size(200, 90);  // just an example
            pan.Controls.Add(l);
            this.Controls.Add(pan);
    
        }
    }
    

提交回复
热议问题