你说用for each .... in 这样的语句有重新resize吗?如果是我已经试过了,因为表单里有frame控件,所以不成功
****************************************************************** Option Explicit Private InitWidth As Long ' Form 的原始大小 Private InitHeight As LongPrivate Sub Form_Load() InitWidth = ScaleWidth InitHeight = ScaleHeight Dim Ctl As Control ' 记录每个 Control 的原始位置、大小、字型大小, 放在 Tag 属性中 On Error Resume Next '确保left, top, width, height, Tag属性没有全有的Control For Each Ctl In Me '也能正常执行 Ctl.Tag = Ctl.Left & " " & Ctl.Top & " " & Ctl.Width & " " & Ctl.Height & " " Ctl.Tag = Ctl.Tag & Ctl.FontSize & " " Next Ctl On Error GoTo 0 End SubPrivate Sub Form_Resize() Dim D(4) As Double Dim I As Long Dim TempPos As Long Dim StartPos As Long Dim Ctl As Control Dim TempVisible As Boolean Dim ScaleX As Double Dim ScaleY As DoubleScaleX = ScaleWidth / InitWidth ScaleY = ScaleHeight / InitHeight On Error Resume Next For Each Ctl In Me TempVisible = Ctl.Visible Ctl.Visible = False StartPos = 1 ' 读取 Control 的原始位置、大小、字型大小 For I = 0 To 4 TempPos = InStr(StartPos, Ctl.Tag, " ", vbTextCompare) If TempPos > 0 Then D(I) = Mid(Ctl.Tag, StartPos, TempPos - StartPos) StartPos = TempPos + 1 Else D(I) = 0 End If ' 根据比例设定 Control 的位置、大小、字型大小 Ctl.Move D(0) * ScaleX, D(1) * ScaleY, D(2) * ScaleX, D(3) * ScaleY 'Ctl.Width = D(2) * ScaleX 'Ctl.Height = D(3) * ScaleY If ScaleX < ScaleY Then Ctl.FontSize = D(4) * ScaleX Else Ctl.FontSize = D(4) * ScaleY End If Next I Ctl.Visible = TempVisible Next Ctl On Error GoTo 0 End Sub ****************************************************************** 表单里有frame控件中控件就不成功。 请问代码里有什么问题吗?
代码一般很长,调试过程也比较麻烦。
用控件.move
Option Explicit
Private InitWidth As Long ' Form 的原始大小
Private InitHeight As LongPrivate Sub Form_Load()
InitWidth = ScaleWidth
InitHeight = ScaleHeight
Dim Ctl As Control
' 记录每个 Control 的原始位置、大小、字型大小, 放在 Tag 属性中
On Error Resume Next '确保left, top, width, height, Tag属性没有全有的Control
For Each Ctl In Me '也能正常执行
Ctl.Tag = Ctl.Left & " " & Ctl.Top & " " & Ctl.Width & " " & Ctl.Height & " "
Ctl.Tag = Ctl.Tag & Ctl.FontSize & " "
Next Ctl
On Error GoTo 0
End SubPrivate Sub Form_Resize()
Dim D(4) As Double
Dim I As Long
Dim TempPos As Long
Dim StartPos As Long
Dim Ctl As Control
Dim TempVisible As Boolean
Dim ScaleX As Double
Dim ScaleY As DoubleScaleX = ScaleWidth / InitWidth
ScaleY = ScaleHeight / InitHeight
On Error Resume Next
For Each Ctl In Me
TempVisible = Ctl.Visible
Ctl.Visible = False
StartPos = 1
' 读取 Control 的原始位置、大小、字型大小
For I = 0 To 4
TempPos = InStr(StartPos, Ctl.Tag, " ", vbTextCompare)
If TempPos > 0 Then
D(I) = Mid(Ctl.Tag, StartPos, TempPos - StartPos)
StartPos = TempPos + 1
Else
D(I) = 0
End If
' 根据比例设定 Control 的位置、大小、字型大小
Ctl.Move D(0) * ScaleX, D(1) * ScaleY, D(2) * ScaleX, D(3) * ScaleY
'Ctl.Width = D(2) * ScaleX
'Ctl.Height = D(3) * ScaleY
If ScaleX < ScaleY Then
Ctl.FontSize = D(4) * ScaleX
Else
Ctl.FontSize = D(4) * ScaleY
End If
Next I
Ctl.Visible = TempVisible
Next Ctl
On Error GoTo 0
End Sub
******************************************************************
表单里有frame控件中控件就不成功。
请问代码里有什么问题吗?
http://www.vbprobe.com/ocx/showdoc.asp?detail_id=508