'在调用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 FormNameobj.Tag = obj.Left & " " & obj.Top & " " & obj.Width & " " & obj.Height & " "Next obj
On Error GoTo 0End Sub'按比例改变表单内各元件的大小, 在调用ReSizeForm前先调用ReSizeInit函数Public Sub ResizeForm(FormName As Form)
Private FormOldWidth As Long '保存窗体的原始宽度
Private FormOldHeight As Long '保存窗体的原始高度
Dim Pos(4) As Double
Dim i As Long, TempPos As Long, startpos As Long
Dim obj As Control
Dim ScaleX As Double, ScaleY As Double
ScaleX = FormName.ScaleWidth / FormOldWidth '保存窗体宽度缩放比例
ScaleY = FormName.ScaleHeight / FormOldHeight '保存窗体高度缩放比例On Error Resume NextFor Each obj In FormName
startpos = 1For i = 0 To 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'根据控件的原始位置及窗体改变大小 的比例对控件重新定位与改变大小obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleYNext iNext objOn Error GoTo 0End Sub这段用了Tag我不想使用TAG
Public Sub ResizeInit(FormName As Form)Dim obj As Control
FormOldWidth = FormName.ScaleWidth
FormOldHeight = FormName.ScaleHeight
On Error Resume Next
For Each obj In FormNameobj.Tag = obj.Left & " " & obj.Top & " " & obj.Width & " " & obj.Height & " "Next obj
On Error GoTo 0End Sub'按比例改变表单内各元件的大小, 在调用ReSizeForm前先调用ReSizeInit函数Public Sub ResizeForm(FormName As Form)
Private FormOldWidth As Long '保存窗体的原始宽度
Private FormOldHeight As Long '保存窗体的原始高度
Dim Pos(4) As Double
Dim i As Long, TempPos As Long, startpos As Long
Dim obj As Control
Dim ScaleX As Double, ScaleY As Double
ScaleX = FormName.ScaleWidth / FormOldWidth '保存窗体宽度缩放比例
ScaleY = FormName.ScaleHeight / FormOldHeight '保存窗体高度缩放比例On Error Resume NextFor Each obj In FormName
startpos = 1For i = 0 To 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'根据控件的原始位置及窗体改变大小 的比例对控件重新定位与改变大小obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleYNext iNext objOn Error GoTo 0End Sub这段用了Tag我不想使用TAG
导致没Tag的值换了。所以没办法。
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()
'oldProc = GetWindowLong(Text1.hwnd, GWL_WNDPROC)
'oldProc = SetWindowLong(Text1.hwnd, GWL_WNDPROC, AddressOf WndProc)
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 Sub Form_Unload(Cancel As Integer)
UnHookText Me.hwnd
End Sub