Basel Awadeen
Basel Awadeen

Reputation: 3

how can when i click the object of button show new object of form2?(C#-Windows form application)

private void gunaButton1_Click(object sender, EventArgs e) { for (int i = 0; i < 1; i++) { GunaButton btn = new GunaButton();

                //add btn to flowlayoutpanel to arrange buttons
                flowLayoutPanel1.Controls.Add(btn);

                Form2 f = new Form2();

                //how can i make object of button show new  object of form2

                btn.Click +=new System.EventHandler(f.ShowDialog());

                
            }

        }

Upvotes: 0

Views: 51

Answers (1)

PINGUIN.ZIP
PINGUIN.ZIP

Reputation: 94

Try:

    btn.Click += new System.EventHandler(this.btn_Click);
    
    private void btn_Click(object sender, EventArgs e)
    {
       Form2 f2 = new Form2();
       f2.ShowDialog();
    }

Upvotes: 0

Related Questions