How To Enumerate Through All Controls On A Form
Article Information
Language:
IDE:
Framework:
Area:
Audience:
VB.NET
Any
1.x
Windows.Forms (Controls)
Beginner, Intermediate, Expert
The Standard Method Of Enumerating Controls On A Form
When you enumerate the controls on a form only the controls whose parent is the form are enumerated. By this I mean that all controls placed directly onto the form will be enumerated but any controls placed into container controls like group boxes will not be enumerated. The code shows the method of enumerating which returns only controls placed directly onto the form.
Standard Enumeration Code
An Enhanced Method Of Enumerating All Controls On A Form
I found the lack of a direct method to enumerate all controls on a form a real nuisance. However, help is at hand. I have created a couple of functions that will enumerate all controls on a form.
Enhanced Enumeration Code
All you need to do is pass a form to the EnumerateAllControlsOnAForm function it will return a Collection of all the controls on a form including all those in container controls.