Form as a Collection

  • Thread starter Thread starter Ricky W. Hunt
  • Start date Start date
R

Ricky W. Hunt

Is there a way to reference all the buttons on a form using a "For Each
button As button In..." without physically putting them in a collection? I
was able to iterate through all the buttons on my if I created a new
collection, then added each button. But is there any way to make the form
itself act like a collection? I.E. is there a way I can:

For Each button As Button In Form1


?

That code doesn't work.
 
Hi,

Try this.


CheckForButton(Me.Controls)



Private Sub CheckForButton(ByVal ctrls As Control.ControlCollection)

For Each ctrl As Control In ctrls

If TypeOf ctrl Is Button Then

Trace.WriteLine(ctrl.Name)

End If

CheckForButton(ctrl.Controls)

Next

End Sub



Ken

---------------------------

Is there a way to reference all the buttons on a form using a "For Each
button As button In..." without physically putting them in a collection? I
was able to iterate through all the buttons on my if I created a new
collection, then added each button. But is there any way to make the form
itself act like a collection? I.E. is there a way I can:

For Each button As Button In Form1


?

That code doesn't work.
 
Back
Top