Re: All Controls On Form Without Using Recursion

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Oopsie indeed. I know how I missed it as well. I created the test
harness I used at work, with a couple of buttons, a panel and a button
on the panel, and cleverly dropped the button over the panel instead
of in it, so everything went blue :)
Well spotted, thanks for the correction :)


On 2 Feb, 12:41, Stefan Hoffmann <stefan.hoffm...@xxxxxxxxxx> wrote:
hi,

DeveloperX wrote:
private void button2_Click(object sender, EventArgs e)
{
System.Collections.Stack toDo = new Stack();
bool working = true;
Control current = null;

foreach (Control c in this.Controls)
{
toDo.Push(c);
}
while (working)
{
current = (Control)toDo.Pop();

Is here not a
toDo.Push(current);
missing?

foreach (Control c2 in current.Controls)
{
toDo.Push(c2);
}
current.BackColor = System.Drawing.Color.AliceBlue;
if (0 == toDo.Count)
{
working = false;
}
}
}

mfG
--> stefan <--


.


Quantcast