不知道7楼的大虾给的程序如何~~~
回复 10楼 pipi_song
'Form改变大小时同时改变其内Control之大小这个程式只是个范例,但在某些物件上不能使用,例如:Line,因为它没有Top, Left Width, Height所以在本程式中没有作用,不过呢,像这一类的东西可自己用另外程式 去控制。Option Explicit
Private InitWidth As Long ' Form 的原始大小
Private InitHeight As Long
Private 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 Sub
Private 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 Double
ScaleX = 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
Me.PaintPicture Me.Picture, 0, 0, ScaleWidth, ScaleHeight '窗体重画
End Sub
'增加倒数第二行 窗体重画 即可,但注意 窗体属性中 autoredraw值 设为true