Zoom 事件、Zoom 属性、Label 控件示例Zoom event, Zoom property, Label control example

以下示例使用**zoom** 事件来计算**zoom** 属性的新值, 并在适当时向窗体添加滚动条。The following example uses the Zoom event to evaluate the new value of the Zoom property and adds scroll bars to the form when appropriate. 该示例使用**标签** 显示当前值。The example uses a Label to display the current value.

用户使用数值**调节钮** 指定窗体的大小, 然后单击**命令按钮** 以在Zoom属性中设置值。The user specifies the size for the form by using the SpinButton, and then clicks the CommandButton to set the value in the Zoom property.

若要使用此示例,请将此示例代码复制到窗体的 Declarations 部分。To use this example, copy this sample code to the Declarations portion of a form. 确保该窗体包含:Make sure that the form contains:

  • 名为 Label1 的 LabelA Label named Label1.
  • 名为 SpinButton1 的 SpinButtonA SpinButton named SpinButton1.
  • 名为 CommandButton1 的 CommandButtonA CommandButton named CommandButton1.
  • 位于窗体边缘附近的其他控件。Other controls placed near the edges of the form.
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

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.