private List<T> GetControls<T>() where T:Control
{
List<T> list = new List<T>();
foreach (Control rootControl in Controls)
{
foreach (Control control in rootControl.Controls)
{
if (control as T != null)
{
list.Add(control as T);
}
}
}
return list;
}
List<Label> list =
GetControls<Label>();
list.ForEach(
delegate (Label lab)
{
lab.BackColor =
System.Drawing.Color.Pink;
}
);
1 comment:
Hi, how deep will this work? I notice you only have 2 loops, what about recursion? - just food for thought.
Post a Comment