Best way to loop thru controls on a form recursively?

What is the most efficient way to loop thru all the controls on a form including controls within container controls?

Who is Participating?
Jacques Bourgeois (James Burger)PresidentCommented:
	Public Sub LoopThroughControls(container As Control)

		For Each ctl As Control In container.Controls
			'Do your stuff here...
			If ctl.Controls.Count > 0 Then
			End If
			'... or here

	End Sub

Open in new window

A form is a Control, so you can send your form to that method, and it will recursively calls itself back when you encounter a Control that contains other Controls.
BlakeMcKennaAuthor Commented:
Thanks James...exactly what I was looking for!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.