Public Sub ArrangeChildren(Father As Control) 'Father为容器控件

（1）对容器控件内的子控件的TabIndex值进行排序

（2）对容器控件内的子控件等间距整齐排列

Dim Child As Control '窗体中的任一控件

Dim Children() As Control '属于容器中的控件数组

Dim Tags() As Integer '元素的值记录了控件的TabIndex值

Dim TempChild As Control '临时控件

Dim i As Integer, j As Integer

Dim x As Integer, Y As Integer

Dim wChild As Integer, hChild As Integer

Dim num As Integer

Dim strTemp As String

num = 0

For Each Child In Father.Parent.Controls ‘搜索容器所在窗体中的每一个控件

If TypeOf Child Is CheckBox Then ‘这个判断是为了提高效率,可不要  If Child.Container Is Father Then

ReDim Preserve Children(num)

ReDim Preserve Tags(num)

Set Children(num) = Child

Children(num).Tag = num

Tags(num) = Children(num).TabIndex

numnum = num + 1

End If

End If

Next

If num < 1 Then Exit Sub ‘当容器中一个子控件也没有时，退出

num = UBound(Children)

SortProc Tags ‘将数组Tags()按由小到大顺序排序

ArrayTagProc Children ‘越在屏幕上面的控件，其<.top>值越小，故让其<.tag>值也小

For i = 0 To num

Children(i).TabIndex = Tags(Children(i).Tag)

Next i ‘越在屏幕上面的控件，其索引值小（实现索引值的排序）

ArrayTabIndexProc Children '

x = 200 ‘控件在其容器中的起始位置

wChild = 4000 ‘控件宽度

hChild = 255 ‘控件高度

Y = (Father.Height - ADJUST - (num + 1) * hChild) / (num + 2)

For j = 0 To num

Children(j).Move x, (j + 1) * Y + j * hChild + ADJUST, wChild, hChild

Next j

End Sub

Public Sub SortProc(ArrInt() As Integer) '对整数数组进行排序

Dim i As Integer, j As Integer

Dim temp As Integer

Dim num As Integer '数组大小

num = UBound(ArrInt)

For i = 0 To num

For j = i + 1 To UBound(ArrInt)

If ArrInt(i) > ArrInt(j) Then

temp = ArrInt(i)

ArrInt(i) = ArrInt(j)

ArrInt(j) = temp

End If  Next j

Next i

End Sub

Public Sub ArrayTabIndexProc(ArrControl() As Control) '对控件数组进行排序

'控件数组ArrControl(0),ArrControl(1),ArrControl(2),.....ArrControl(n)

'的TabIndex值按由低到高顺序排列

Dim i As Integer, j As Integer

Dim temp As Control

Dim num As Integer

num = UBound(ArrControl)

For i = 0 To num

For j = i + 1 To UBound(ArrControl)

If ArrControl(i).TabIndex > ArrControl(j).TabIndex Then

Set temp = ArrControl(i)

Set ArrControl(i) = ArrControl(j)

Set ArrControl(j) = temp

End If

Next j

Next i

End Sub

Public Sub ArrayTagProc(arr() As Control) '对控件的<.tag>属性进行排序

'越在屏幕上面的控件，其<.top>值越小，故让其<.tag>值也小（最综的目的是让其索引值小）

Dim i As Integer, j As Integer

Dim temp As Variant

Dim num As Integer

Dim arrTop() As Integer '存储控件<.Top属性>数组

num = UBound(arr)

ReDim arrTop(num)

For i = 0 To num

arrTop(i) = arr(i).Top

Next

SortProc arrTop '按照由小到大顺序

For i = 0 To num

For j = 0 To num

If arr(i).Top = arrTop(j) Then arr(i).Tag = j

Next j

Next i

End Sub