Ha! I get it....
I am actually using an adaptation of this technique in production code.
But the adapted code required a dept-first
search and this original pattern is width-first
.
Which brings us these new and improved versions:
public static List<control> FindControlsWidthFirst( Control controlTop )
{
List<control> list = new List<control>();
list.Add(controlTop);
for (int i = 0; i < list.Count; ++i)
{
list.AddRange(list[i].Controls);
}
return list;
}
public static List<control> FindControlsDepthFirst( Control controlTop )
{
List<control> list = new List<control>();
list.Add(controlTop);
for (int i = 0; i < list.Count; ++i)
{
list.InsertRange(i + 1, list[i].Controls);
}
return list;
}
</control></control></control></control>