📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 8145
ClientLeft = 60
ClientTop = 450
ClientWidth = 7020
LinkTopic = "Form1"
ScaleHeight = 8145
ScaleWidth = 7020
StartUpPosition = 3 '窗口缺省
Begin VB.PictureBox Picture2
Height = 855
Left = 1080
ScaleHeight = 795
ScaleWidth = 4995
TabIndex = 3
Top = 6720
Width = 5055
End
Begin VB.PictureBox Picture1
Height = 2895
Left = 3480
ScaleHeight = 2835
ScaleWidth = 1635
TabIndex = 2
Top = 1680
Width = 1695
End
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 1095
Left = 1200
TabIndex = 1
Top = 2400
Width = 495
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 1095
Left = 960
TabIndex = 0
Top = 600
Width = 855
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -