【发布时间】:2017-07-05 20:48:21
【问题描述】:
我正在寻找一些关于如何将点击事件处理程序添加到已在循环中动态创建的标签的建议。
我已经在动态创建的控件上搜索了单击事件处理程序,但这总是会返回不在数组中的单个控件。
代码示例:
//create an array of 16 labels
Label[] label = new Label[16];
//loop through the array of labels
for (int i = 0; i < label.Length; i++)
{
label[i] = new Label(); //create new label
label[i].Name = "lbl" + i.ToString(); //give the label a name
label[i].Text = "label " + i.ToString(); //give the label text
}
任何关于这方面的帮助和建议都会很棒,谢谢!
【问题讨论】:
标签: c# winforms user-interface dynamic controls