0

I am a begginer in C# and I want to create a button which creates button. but these buttons never appear...

please find my code :

    private void addstrat3_i_Click(object sender, EventArgs e)
    {
        panel3strat.Width += 200;
        Button addstrat3_2 = new Button();
        addstrat3_2.Size = new Size(210, 41);
        addstrat3_2.Location = new Point(50,50);
        addstrat3_2.Visible = true; 
    }

Thanks a lot

4

2 回答 2

10

您必须使用该Controls属性在表单上添加按钮(或任何其他控件),例如:

private void addstrat3_i_Click(object sender, EventArgs e)
{
    panel3strat.Width += 200;
    Button addstrat3_2 = new Button();
    addstrat3_2.Size = new Size(210, 41);
    addstrat3_2.Location = new Point(50,50);
    addstrat3_2.Visible = true; 

    // add control
    this.Controls.Add(addstrat3_2);    
}
于 2013-04-29T14:54:48.457 回答
3

您需要将按钮添加到表单中。

this.Controls.Add(addstrat3_2);
于 2013-04-29T14:55:04.590 回答