LargeChange、SmallChange 属性示例LargeChange, SmallChange properties example

下面的示例演示在与独立**滚动条** 一起使用时的**LargeChange** 和**SmallChange** 属性。The following example demonstrates the LargeChange and SmallChange properties when used with a stand-alone ScrollBar. The user can set the LargeChange and SmallChange values to any integer in the range of 0 to 100.The user can set the LargeChange and SmallChange values to any integer in the range of 0 to 100.

此示例还使用**MaxLength** 属性来限制为LargeChangeSmallChange值输入的字符数。This example also uses the MaxLength property to restrict the number of characters entered for the LargeChange and SmallChange values.

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

  • 名为 Label1 的**标签** 和名为 TextBox1 的**TextBox** 。A Label named Label1 and a TextBox named TextBox1.
  • 名为 Label2 的 Label 和名为 TextBox2 的 TextBoxA Label named Label2 and a TextBox named TextBox2.
  • 名为 ScrollBar1 的 ScrollBarA ScrollBar named ScrollBar1.
  • 名为 Label3 的 LabelA Label named Label3.
Dim TempNum As Integer 
 
Private Sub ScrollBar1_Change() 
 Label3.Caption = ScrollBar1.Value 
End Sub 
 
Private Sub TextBox1_Change() 
 If IsNumeric(TextBox1.Text) Then 
 TempNum = CInt(TextBox1.Text) 
 If TempNum >= 0 And TempNum <= 100 Then 
 ScrollBar1.SmallChange = TempNum 
 Else 
 TextBox1.Text = ScrollBar1.SmallChange 
 End If 
 Else 
 TextBox1.Text = ScrollBar1.SmallChange 
 End If 
End Sub 
 
Private Sub TextBox2_Change() 
 If IsNumeric(TextBox2.Text) Then 
 TempNum = CInt(TextBox2.Text) 
 If TempNum >= 0 And TempNum <= 100 Then 
 ScrollBar1.LargeChange = TempNum 
 Else 
 TextBox2.Text = ScrollBar1.LargeChange 
 End If 
 Else 
 TextBox2.Text = ScrollBar1.LargeChange 
 End If 
End Sub 
 
Private Sub UserForm_Initialize() 
 ScrollBar1.Min = -1000 
 ScrollBar1.Max = 1000 
 
 Label1.Caption = "SmallChange 0 to 100" 
 ScrollBar1.SmallChange = 1 
 TextBox1.Text = ScrollBar1.SmallChange 
 TextBox1.MaxLength = 3 
 
 Label2.Caption = "LargeChange 0 to 100" 
 ScrollBar1.LargeChange = 100 
 TextBox2.Text = ScrollBar1.LargeChange 
 TextBox2.MaxLength = 3 
 
 ScrollBar1.Value = 0 
 Label3.Caption = ScrollBar1.Value 
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.