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

Time:06-15

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

                
            }

        }

CodePudding user response:

Try:

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