Results 1 to 2 of 2

Thread: How do I get all controls on a form? [resolved]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Posts
    164

    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

  2. #2
    Addicted Member PeteD's Avatar
    Join Date
    Jun 2003
    Location
    Sydney
    Posts
    158
    best to use a recursive method:

    VB Code:
    1. RecursiveMethod(YourForm)
    2.  
    3.    Private Sub RecursiveMethod(ByVal control As Control)
    4.       MessageBox.Show(control.Name)
    5.       If control.Controls.Count > 0 Then   ' If the control holds other controls, iterate through them also.
    6.          For Each childControl As Control In control.Controls
    7.             RecursiveMethod(childControl)
    8.          Next
    9.       End If
    10.    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
  •  



Click Here to Expand Forum to Full Width