I do remember seeing someone ask something along these lines a while ago but I did a search and couldn\'t find anything.
I\'m trying to come up with the cleanest wa
I voted for Nathan's solution, but wanted to add a bit more than a comment can handle.
His is actually very good, but I think the best solution would involve sub-classing each of the control types you might be adding before adding them to the GUI. Have them all implement an interface "Clearable" or something like that (I'm a java programmer, but the concept should be there), then iterate over it as a collection of "Clearable" objects, calling the only method .clear() on each
This is how GUIs really should be done in an OO system. This will make your code easy to extend in the future--almost too easy, you'll be shocked.
Edit: (per Nathan's comment about not changing existing controls)
Perhaps you could create "Container" classes that reference your control (one for each type of control). In a loop like the one you set up in your answer, you could instantiate the correct container, place the real control inside the container and store the container in a collection.
That way you are back to iterating over a collection.
This would be a good simple solution that isn't much more complex than the one you suggested, but infinitely more expandable.