c#如何给动态的一组添加的按钮添加事件

我添加的是是一组按钮,然后点击一个按钮可以打开一个界面,界面中可以显示该按钮的名字 是用winform做的

private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
Button p = new Button();
this.Controls.Add(p);
p.Click += new EventHandler(Button_Click);
}
}

void Button_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-09-28
动态添加的按钮?

先通过findcontrol找到按钮
Button btn=(Button)this.FindControl("id");
btn.Attribute.Add("事件函数");
相似回答