3Q!
看我的代码(节选):(证明:Resize事件触发了Load事件)
'*****************************************************************************
'下面是窗体部分代码
'3============================================================================
'窗体Load事件
Private Sub Form_Load()
'3.1----------------------------------------------------------------------
'声明部分
Static arrButCap(1 To intButNum - 1) As String '存放各动态加载的按扭的标题
'3.2----------------------------------------------------------------------
'初始化数组
arrButCap(1) = "工单管理"
arrButCap(2) = "工票管理"
arrButCap(3) = "终端管理"
arrButCap(4) = "工艺管理"
arrButCap(5) = "工序管理"
'3.3----------------------------------------------------------------------
'初始化导航按扭
For i = 1 To intButNum - 1
'3.3.1----------------------------------------------------------------
'加载导航按扭
Load cmdNav(i)
'3.3.2----------------------------------------------------------------
'初始化导航按扭移动方向
boolMoveWay(i) = False
'3.3.3----------------------------------------------------------------
'初始化导航按扭标题、位置、可见性
With cmdNav(i)
.Caption = arrButCap(i)
.Visible = True
.Top = i * 500
End With
Next i
'3.4----------------------------------------------------------------------
'初始化窗体尺寸改变工作
Call ResizeInit(Form1)
End Sub
'4============================================================================
'窗体Resize事件
Private Sub Form_Resize()
For i = 0 To 5
boolMoveWay(i) = False
Next i
Call ResizeForm(Form1)
End Sub
'******************************************************************************
下面是模块部分:
Option Explicit
'****************************************************************
'说明:
'1 模块级变量声明部分
'2 ResizeInit() 改变窗体尺寸前进行初始化工作的函数
'3 ResizeForm() 改变窗体内各元件尺寸的函数
'****************************************************************
'1===============================================================
'声明部分
Private FormOldWidth As Long '保存窗体的原始宽度
Private FormOldHeight As Long '保存窗体的原始高度
'2===============================================================
'在调用ResizeForm前先调用本函数
Public Sub ResizeInit(FormName As Form)
Dim Obj As Control
FormOldWidth = FormName.ScaleWidth
FormOldHeight = FormName.ScaleHeight
On Error Resume Next
For Each Obj In FormName
Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.Height & " "
Next Obj
On Error GoTo 0
End Sub
'3================================================================
'按比例改变表单内各元件的大小,在调用ReSizeForm前先调用ReSizeInit函数
Public Sub ResizeForm(FormName As Form)
'3.1----------------------------------------------------------
'局部变量声明部分
Dim Pos(4) As Double
Dim i As Long, TempPos As Long, StartPos As Long
Dim Obj As Control
Dim ScaleX As Double '保存窗体宽度缩放比例
Dim ScaleY As Double '保存窗体高度缩放比例
'3.2----------------------------------------------------------
'保存窗体缩放比例
ScaleX = FormName.ScaleWidth / FormOldWidth
ScaleY = FormName.ScaleHeight / FormOldHeight
On Error Resume Next
'3.3----------------------------------------------------------
'对FormName集合中的各元件执行3.4,3.5操作
For Each Obj In FormName
StartPos = 1
For i = 0 To 4
'3.4--------------------------------------------------
'读取控件的原始位置与大小
TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare)
If TempPos > 0 Then
Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos)
StartPos = TempPos + 1
Else
Pos(i) = 0
End If
'3.5--------------------------------------------------
'根据控件的原始位置及窗体改变大小的比例对控件重新定位与改变大小
Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY
Next i
Next Obj
On Error GoTo 0
End Sub