【发布时间】:2014-07-04 10:37:38
【问题描述】:
我有 180 个标签并在运行 180 次的 for 循环中检查条件。如何在循环中更改每个特定标签的标签颜色?
我的代码:
for (Int16 i = 1; i < 181; i++)
{
try
{
// Do some thing
}
catch (Exception ex)
{
// this works for only one label i want to make it
// dynamic like below..and i want to make color change if it catch
// any Exception for the respective loop.
label1.ForeColor = Color.Blue;
// this doesn't works
label[i].ForeColor = Color.Blue;
}
finally
{
//Do nothing
}
}
【问题讨论】:
-
您是否收到错误消息?
-
如果您使用的是网络,那么有一种方法可以通过名称获取元素。
标签: c# arrays loops colors label