我百度到专家答疑网上面的一个解答:'下面代码使得窗体大小变化时窗体内各控件大小和位置按窗体变化比例变化,测试过后控件是变化了,加上什么代码也能把文字也随之变化呢?
------------------------------------------------------
Option Explicit
Private Type mForm
height As Single
width As Single
End Type
Private Type mControl
top As Single
left As Single
height As Single
width As Single
End Type
Private myForm As mForm, myControls() As mControl
----------------------------------------------------
Private Sub Form_Load()
myForm.height = Me.height
myForm.width = Me.width
ReDim myControls(Controls.Count - 1)
Dim i As Long
For i = 0 To Controls.Count - 1
myControls(i).top = Controls(i).top
myControls(i).left = Controls(i).left
myControls(i).height = Controls(i).height
myControls(i).width = Controls(i).width
Next i
End Sub
----------------------------------------------------
Private Sub Form_Resize()
Dim hRatio As Single, wRatio As Single
hRatio = Me.height / myForm.height
wRatio = Me.width / myForm.width
Dim i As Long
For i = 0 To Controls.Count - 1
Controls(i).top = myControls(i).top * hRatio
Controls(i).height = myControls(i).height * hRatio
Controls(i).left = myControls(i).left * wRatio
Controls(i).width = myControls(i).width * wRatio
Next i
On Error Resume Next
End Sub
---------------------------------------------------
求教吧里的老师们。
------------------------------------------------------
Option Explicit
Private Type mForm
height As Single
width As Single
End Type
Private Type mControl
top As Single
left As Single
height As Single
width As Single
End Type
Private myForm As mForm, myControls() As mControl
----------------------------------------------------
Private Sub Form_Load()
myForm.height = Me.height
myForm.width = Me.width
ReDim myControls(Controls.Count - 1)
Dim i As Long
For i = 0 To Controls.Count - 1
myControls(i).top = Controls(i).top
myControls(i).left = Controls(i).left
myControls(i).height = Controls(i).height
myControls(i).width = Controls(i).width
Next i
End Sub
----------------------------------------------------
Private Sub Form_Resize()
Dim hRatio As Single, wRatio As Single
hRatio = Me.height / myForm.height
wRatio = Me.width / myForm.width
Dim i As Long
For i = 0 To Controls.Count - 1
Controls(i).top = myControls(i).top * hRatio
Controls(i).height = myControls(i).height * hRatio
Controls(i).left = myControls(i).left * wRatio
Controls(i).width = myControls(i).width * wRatio
Next i
On Error Resume Next
End Sub
---------------------------------------------------
求教吧里的老师们。