Zoom 事件、Zoom 属性和标签控件示例
下例使用 Zoom 事件来计算 Zoom 属性的新值,并在适当的时候把滚动条加到窗体。该示例使用标签来显示当前数值。用户通过数值调节钮确定窗体的尺寸,然后单击命令按钮,设置 Zoom 属性中的数值。
窗体包含:
- 名为 Label1 的标签。
- 名为 SpinButton1 的数值调节钮。
- 名为 CommandButton1 的命令按钮。
- 放置在靠近窗体边缘位置的其他控件。
示例
Sub CommandButton1_Click()
Zoom = SpinButton1.Value
End Sub
Sub SpinButton1_SpinDown()
Label1.Caption = SpinButton1.Value
End Sub
Sub SpinButton1_SpinUp()
Label1.Caption = SpinButton1.Value
End Sub
Sub UserForm_Initialize()
SpinButton1.Min = 10
SpinButton1.Max = 400
SpinButton1.Value = 100
Label1.Caption = SpinButton1.Value
CommandButton1.Caption = "Zoom it!"
End Sub
Sub UserForm_Zoom(Percent As Integer)
Dim MyResult As Double
If Percent > 99 Then
ScrollBars = fmScrollBarsBoth
ScrollLeft = 0
ScrollTop = 0
MyResult = Width * Percent / 100
ScrollWidth = MyResult
MyResult = Height * Percent / 100
ScrollHeight = MyResult
Else
ScrollBars = fmScrollBarsNone
ScrollLeft = 0
ScrollTop = 0
End If
End Sub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41