Winform多个控件执行不同操作
int[] Result_result = new int[] { 0, 1, 0, 1, 0, 1, }; //0置button背景颜色为红,1为绿
private void button1_Click(object sender, EventArgs e)
{
string name = "button";
int i;
//遍历groupbox1里面的控件
for (i = 0; i < 6; i++)
{
name = String.Concat(name, i.ToString());
foreach (Control Item in groupBox1.Controls)
{
if (Item.Name == name)
{
if(Result_result[i] == 0)
{
Item.BackColor = Color.Red;
}
else
{
Item.BackColor = Color.Green;
}
}
}
name = "button";
}
}
运行结果示例如下