Option Explicit Private Type ControlSize name As String '控件名称 x As Single '左边距比例 y As Single '右边距比例 cx As Single '宽度比例 cy As Single '长度比例 End Type Dim arrSize() As ControlSize Private Sub Form_Load() ReDim arrSize(0) As ControlSize SaveSize Command1 SaveSize Command2 End SubPrivate Sub Form_Resize() If Me.WindowState = 1 Then Exit Sub End If Resize Command1 Resize Command2 End SubPrivate Sub Resize(obj As Object) Dim i As Integer Dim j As Integer j = UBound(arrSize()) For i = 1 To j If arrSize(i).name = obj.name Then Exit For End If Next i If i > j Then Exit Sub Else obj.Left = arrSize(i).x * Me.ScaleWidth obj.Top = arrSize(i).y * Me.ScaleHeight obj.Width = arrSize(i).cx * Me.ScaleWidth obj.Height = arrSize(i).cy * Me.ScaleHeight End If
End SubPrivate Sub SaveSize(obj As Object) Dim count As Integer count = UBound(arrSize) ReDim Preserve arrSize(count + 1) arrSize(count + 1).name = obj.name arrSize(count + 1).x = obj.Left / Me.ScaleWidth arrSize(count + 1).y = obj.Top / Me.ScaleHeight arrSize(count + 1).cx = obj.Width / Me.ScaleWidth arrSize(count + 1).cy = obj.Height / Me.ScaleHeight End Sub
Private Type ControlSize
name As String '控件名称
x As Single '左边距比例
y As Single '右边距比例
cx As Single '宽度比例
cy As Single '长度比例
End Type
Dim arrSize() As ControlSize
Private Sub Form_Load()
ReDim arrSize(0) As ControlSize
SaveSize Command1
SaveSize Command2
End SubPrivate Sub Form_Resize()
If Me.WindowState = 1 Then
Exit Sub
End If
Resize Command1
Resize Command2
End SubPrivate Sub Resize(obj As Object)
Dim i As Integer
Dim j As Integer
j = UBound(arrSize())
For i = 1 To j
If arrSize(i).name = obj.name Then
Exit For
End If
Next i
If i > j Then
Exit Sub
Else
obj.Left = arrSize(i).x * Me.ScaleWidth
obj.Top = arrSize(i).y * Me.ScaleHeight
obj.Width = arrSize(i).cx * Me.ScaleWidth
obj.Height = arrSize(i).cy * Me.ScaleHeight
End If
End SubPrivate Sub SaveSize(obj As Object)
Dim count As Integer
count = UBound(arrSize)
ReDim Preserve arrSize(count + 1)
arrSize(count + 1).name = obj.name
arrSize(count + 1).x = obj.Left / Me.ScaleWidth
arrSize(count + 1).y = obj.Top / Me.ScaleHeight
arrSize(count + 1).cx = obj.Width / Me.ScaleWidth
arrSize(count + 1).cy = obj.Height / Me.ScaleHeight
End Sub