1,451
社区成员
发帖
与我相关
我的任务
分享
Dim f_size(1) As Long, fist_re As Boolean '用来存放窗体默认大小 以及 是否第一次初始化,全局变量,可在 模块中public声明
Private Sub Form_Resize()
If Me.WindowState <> 1 Then '必须排除最小化的状态
If fist_re = False Then '窗体初始化只记录窗体大小
f_size(0) = Me.Height: f_size(1) = Me.Width
fist_re = True
Else '否则开始适应屏幕变化
For Each a In Form1.Controls
On Error Resume Next
a.Width = a.Width * (Me.Width / f_size(1))
a.Height = a.Height * (Me.Height / f_size(0))
a.Top = a.Top * (Me.Height / f_size(0))
a.Left = a.Left * (Me.Width / f_size(1))
Next
f_size(0) = Me.Height: f_size(1) = Me.Width '重新记录窗口大小,用于下次运算
End If
End If
End Sub