【发布时间】:2014-04-01 16:15:19
【问题描述】:
所以,我有一个用文本框和按钮动态填充的表单。 如何为每个按钮动态创建事件处理程序(例如:它生成 20 个按钮,我需要 20 个事件处理程序)。每个按钮都将具有相同的功能(从数据库中删除某些内容),但我需要程序知道何时单击其中任何一个来触发该代码。 // 另外,按钮创建代码在 while() 内,所以我不能在 while 之外使用它(只是指出这一点) 代码:
public void LoadElements()
{
//more code here
while(some condition)
{
// more code above
Button b = new Button();
b.Text = "Delete";
b.Name = "button" + j;
b.Location = new Point(240, Y);
Controls.Add(b);
// more code bellow
}
// more code here
}
【问题讨论】:
标签: c# visual-studio-2010 events button