form1 から form2 にクリック イベントを動的に追加したいと考えています。
これはform1の私のコードです:
Form2 frm = new Form2();
string title =(string)listBox1.SelectedItem;
TabPage myTabPage = new TabPage(title);
frm.tabControl1.TabPages.Add(myTabPage);
//create button and it's event
Button button1 = new Button();
button1.Click += new System.EventHandler(button1_Click);
button1.Location = new Point((myTabPage.Width/2)-(button1.Width/2),myTabPage.Height-30);
button1.Text = "Click On Me!";
myTabPage.Controls.Add(button1);
frm.Show();
次のエラーが表示されます: The name 'button1_Click' does not exist in the current context
助けてください。