我想动态地将点击事件从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();
我得到以下错误: “的button1_Click”这个名字不会在目前情况下
请帮忙存在。
哟定义button1_Click在新表单上的任何地方?如果不是,则必须在将其绑定到任何按钮单击事件之前对其进行定义。 – donstack