以前写的一个小东西,也许对你有用. '模块使用说明 '3 模块中已经包括对缩放比例的检查 '6 窗体内的控件字体被改为宋体 '7 窗体的bordstyle 设置为1 Public Sub formresize(pro As String, Form1 As Form, mscale As Single) Dim proportion As Single Dim exist As Boolean Dim i As Integer Dim j As Integer Dim editstr As String On Error Resume Next '要保存原始比例 proportion = ScaleOk(pro) proportion = proportion * mscale ''高2000 宽2000 If Form1.Width * proportion < 1000 Or Form1.Height * proportion < 1000 Then MsgBox "尺寸过小显示将不正常", 64, "提示" Exit Sub End If
If proportion = 1 Then Exit Sub mscale = (1 / proportion) * mscale With Form1 .Width = .Width * proportion .Height = .Height * proportion End With
For Each ctl In Form1.Controls On Error Resume Next If TypeOf ctl Is RichTextBox Then '只能缩放字符 ctl.Font = "宋体" ctl.Left = ctl.Left * proportion ctl.Top = ctl.Top * proportion ctl.Height = ctl.Height * proportion ctl.Width = ctl.Width * proportion ctl.SelFontSize = ctl.SelFontSize * proportion ' editstr = ctl.Text ' ctl.Text = "" ' ctl.SelFontSize = ctl.SelFontSize * proportion ' ctl.SelText = editstr Else With ctl .Font = "宋体" .Left = .Left * proportion .Top = .Top * proportion .Height = .Height * proportion .Width = .Width * proportion .FontSize = .FontSize * proportion End With End If NextEnd Sub
'模块使用说明
'3 模块中已经包括对缩放比例的检查
'6 窗体内的控件字体被改为宋体
'7 窗体的bordstyle 设置为1
Public Sub formresize(pro As String, Form1 As Form, mscale As Single)
Dim proportion As Single
Dim exist As Boolean
Dim i As Integer
Dim j As Integer
Dim editstr As String
On Error Resume Next
'要保存原始比例
proportion = ScaleOk(pro)
proportion = proportion * mscale
''高2000 宽2000
If Form1.Width * proportion < 1000 Or Form1.Height * proportion < 1000 Then
MsgBox "尺寸过小显示将不正常", 64, "提示"
Exit Sub
End If
If proportion = 1 Then Exit Sub
mscale = (1 / proportion) * mscale
With Form1
.Width = .Width * proportion
.Height = .Height * proportion
End With
For Each ctl In Form1.Controls
On Error Resume Next
If TypeOf ctl Is RichTextBox Then '只能缩放字符
ctl.Font = "宋体"
ctl.Left = ctl.Left * proportion
ctl.Top = ctl.Top * proportion
ctl.Height = ctl.Height * proportion
ctl.Width = ctl.Width * proportion
ctl.SelFontSize = ctl.SelFontSize * proportion
' editstr = ctl.Text
' ctl.Text = ""
' ctl.SelFontSize = ctl.SelFontSize * proportion
' ctl.SelText = editstr
Else
With ctl
.Font = "宋体"
.Left = .Left * proportion
.Top = .Top * proportion
.Height = .Height * proportion
.Width = .Width * proportion
.FontSize = .FontSize * proportion
End With
End If
NextEnd Sub
如果是局部的变量,在引用前定义就行了