I have a form with a number of controls on it, and I had thought that the "Controls" property of the form instance contained all of the controls on the form as per the documentation.

Actually it does, but now iterating over all of my controls becomes similar to iterating over all the files in a directory structure, recursing subdirectories (groupboxes are now like folders).

So.. is there a generic algorithm for this in the standard library?

It could be a time saver knowing of this when using lots of nested groupboxes, btw.

Each Control has a Parent attribute, so you could use something like the following Linq statement to get just the "top-most" controls.

var controls = this.Controls.Where(o => o.Parent.Equals(this));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.