Zoom 事件、Zoom 属性、Label 控件示例

以下示例使用 Zoom 事件评估 Zoom 属性的新值,并在适当时向窗体添加滚动条。 该示例使用 Label 显示当前值。

用户通过使用 SpinButton 指定窗体的大小,然后单击 CommandButton 以在 Zoom 属性中设置值。

若要使用此示例,请将此示例代码复制到窗体的 Declarations 部分。 确保该窗体包含:

  • 名为 Label1 的 Label
  • 名为 SpinButton1 的 SpinButton
  • 名为 CommandButton1 的 CommandButton
  • 位于窗体边缘附近的其他控件。
Private Sub CommandButton1_Click() 
 Zoom = SpinButton1.Value 
End Sub 
 
Private Sub SpinButton1_SpinDown() 
 Label1.Caption = SpinButton1.Value 
End Sub 
 
Private Sub SpinButton1_SpinUp() 
 Label1.Caption = SpinButton1.Value 
End Sub 
 
Private Sub UserForm_Initialize() 
 SpinButton1.Min = 10 
 SpinButton1.Max = 400 
 SpinButton1.Value = 100 
 Label1.Caption = SpinButton1.Value 
 
 CommandButton1.Caption = "Zoom it!" 
End Sub 
 
Private 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

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。