There are a few ways you could achieve this ...
For example: Calculate the positions on the fly ... this snippet works but isn't very tidy
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, y As Integer
x = 0
y = 0
For Each c As Control In Me.Controls
If TypeOf (c) Is GroupBox Then
c.Left = y
c.Top = x
If c.Visible Then
If y + c.Width <= Me.Width - c.Width Then
y += c.Width
Else
y = 0
x += c.Height
End If
End If
End If
Next
End Sub
It attempts to get a best fit based on space left. Disadvantage is that you can't control the order that the controls are returned (well you can but it is fiddly)
Or you could have a set of pre-defined locations in a list and just move the groupboxes into them e.g.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim locations As New List(Of System.Drawing.Point)
Dim l As System.Drawing.Point = New System.Drawing.Point(1, 0)
locations.Add(l)
l = New System.Drawing.Point(98, 0)
locations.Add(l)
l = New System.Drawing.Point(195, 0)
locations.Add(l)
l = New System.Drawing.Point(1, 67)
locations.Add(l)
Dim i As Integer
Dim j As Integer
For i = 1 To 4
Dim g As GroupBox = Me.Controls.Find("GroupBox" + i.ToString(), True)(0)
If g.Visible Then
g.Location = locations(j)
j += 1
End If
Next
End Sub
NB - I've put all of the positions into this button click event - this is not the best approach. Nor did I use
Imports System.Drawing
The second method depends on all of the Groupboxes being named with a suffix of 1, 2, 3, etc