Get all TextBoxes in a VB.net/form (recursive)

When a control is specified in getControl, all TextBoxes and ComboBoxes in the control are returned. Since we are searching recursively, it also returns all the elements inside TabPage and so on.

[cc lang="vb"]
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.
For Each control As Control In getControls(Me)
Console.WriteLine(control.Name && ":" && control.Text)
next
End Sub

Private Function getControls(target As Control) As ArrayList
Dim controls As ArrayList = New ArrayList
For Each control As Control In target.Controls
If TypeOf control Is TextBox Then controls.Add(control)
If TypeOf control Is ComboBox Then controls.Add(control)
If control.HasChildren Then controls.AddRange(getControls(control))
next
Return controls
End Function
[/cc]

en_USEnglish