C# 如何在代码中对所有button控件操作啊
List<Control> buttonList = new List<Control>();
foreach (Control control in Controls) //遍历所以的控件
{
if (control is Button) //判断是否是按钮控件
{
buttonList.add(control );
}
}
这样你就可以只操作buttonList了。
设置属性的时候,同样要遍历buttonList
for(int i = 0;i < buttonList.Count;i++)
{
Button b = buttonList[i] as Button;
b.Text = "xxxxx"; //等等属性之类的东西
}
留言列表: