Tomato Ketchup
Tomato Ketchup

Reputation: 27

Create a button which creates button

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

Upvotes: 0

Views: 157

Answers (2)

Felipe Oriani
Felipe Oriani

Reputation: 38598

You have to add the button (or any other controls) on the form using the Controls property, for sample:

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

Upvotes: 10

Kestami
Kestami

Reputation: 2073

You need to add the button to the form.

this.Controls.Add(addstrat3_2);

Upvotes: 3

Related Questions