Loops in Visual Basic
All of the controls on a form makeup a collection. The For Each loop can be used to loop through each object in a collection.
Start a new application and place a few controls of various types on the form.
Write the code to arrange the controls in Form Load:
'Use For Each to align the controls
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim myControl As Control
Dim Y As Integer
For Each myControl In Me.Controls
myControl.SetBounds(0, Y, myControl.Width, myControl.Height)
Y += myControl.Height + 10
At run time the controls are arranged neatly.