|
-
Aug 20th, 2003, 12:49 PM
#1
Thread Starter
Addicted Member
How do I get all controls on a form? [resolved]
I'm trying to loop through each control on my form, but tabcontrols, tabpages, groupboxes, etc. are getting in my way. Is there anyway that I can get all controls at the form level, without having to loop through each groupbox of each tabpage of each tabcontrol?
(Add a form, add a tabcontrol, then add a few controls and controls within groupboxes to a few tabpages, then try to loop through all of that.)
When I try me.controls, it only returns the tabcontrols. Then I try me.tabcontrol1.controls, then it only returns the tabpages. Then when try me.tablcontrol1.tabpage(0).controls, then it only returns the groupboxes.
I don't want to create multiple loops for each tabcontrol\tabpage\groupbox (because not all controls are in the bottom level), I just want to loop through each control on the entire form.
thanks
Last edited by Shurijo; Aug 21st, 2003 at 10:51 AM.
-Shurijo
-
Aug 20th, 2003, 01:52 PM
#2
Addicted Member
best to use a recursive method:
VB Code:
RecursiveMethod(YourForm)
Private Sub RecursiveMethod(ByVal control As Control)
MessageBox.Show(control.Name)
If control.Controls.Count > 0 Then ' If the control holds other controls, iterate through them also.
For Each childControl As Control In control.Controls
RecursiveMethod(childControl)
Next
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|