LargeChange 和 SmallChange 属性示例

下例演示当与独立滚动条一起使用时 LargeChange 和 SmallChange 的属性。用户可以把 LargeChange 和 SmallChange 值设置为 0 到 100 范围内的任何整数。该示例还用 MaxLength 属性来限定作为 LargeChange 和 SmallChange 值的输入字符数。

窗体包含:

  • 名为 Label1 的标签和名为 TextBox1 的文本框。
  • 名为 Label2 的标签和名为 TextBox2 的文本框。
  • 名为 ScrollBar1 的滚动条。
  • 名为 Label3 的标签。
Dim TempNum

Sub UserForm_ScrollBar1_Change()
    UserForm_Label3.Caption = UserForm_ScrollBar1.Value
End Sub

Sub UserForm_TextBox1_Change()
    If IsNumeric(UserForm_TextBox1.Text) Then
        TempNum = CInt(UserForm_TextBox1.Text)
        If TempNum >= 0 And TempNum <= 100 Then
            UserForm_ScrollBar1.SmallChange = TempNum
        Else
            UserForm_TextBox1.Text = UserForm_ScrollBar1.SmallChange
        End If
    Else
        UserForm_TextBox1.Text = UserForm_ScrollBar1.SmallChange
    End If
    
End Sub

Sub UserForm_TextBox2_Change()
    If IsNumeric(UserForm_TextBox2.Text) Then
        TempNum = CInt(UserForm_TextBox2.Text)
        If TempNum >= 0 And TempNum <= 100 Then
            UserForm_ScrollBar1.LargeChange = TempNum
        Else
            TextBox2.Text = UserForm_ScrollBar1.LargeChange
        End If
    Else
        UserForm_TextBox2.Text = UserForm_ScrollBar1.LargeChange
    End If

End Sub

Sub UserForm_Initialize()
    UserForm_ScrollBar1.Min = -1000
    UserForm_ScrollBar1.Max = 1000
    
    UserForm_Label1.Caption = "SmallChange 0 to 100"
    UserForm_ScrollBar1.SmallChange = 1
    UserForm_TextBox1.Text = UserForm_ScrollBar1.SmallChange
    UserForm_TextBox1.MaxLength = 3
    
    UserForm_Label2.Caption = "LargeChange 0 to 100"
    UserForm_ScrollBar1.LargeChange = 100
    UserForm_TextBox2.Text = UserForm_ScrollBar1.LargeChange
    UserForm_TextBox2.MaxLength = 3
    
    UserForm_ScrollBar1.Value = 0
    UserForm_Label3.Caption = UserForm_ScrollBar1.Value
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
42
43
44
45
46
47
48
49
50
51
52