ListStyle 和 MultiSelect 属性示例
下例用 ListStyle 和 MultiSelect 属性来控制列表框的外观。用户用切换按钮为 ListStyle 选择一个值,并为一个 MultiSelect 值选择数值调节钮。列表框的外观随列表框内的选定行为发生相应的变化。
窗体包含:
- 名为 ListBox1 的列表框。
- 名为 Label1 的标签。
- 名为从 OptionButton1 到 OptionButton3 的三个选项按钮控件。
- 名为 ToggleButton1 的切换按钮。
Sub UserForm_Initialize()
Dim i
For i = 1 To 8
UserForm_ListBox1.AddItem "Choice" & (UserForm_ListBox1.ListCount + 1)
Next
UserForm_Label1.Caption = "MultiSelect Choices"
UserForm_Label1.AutoSize = True
UserForm_ListBox1.MultiSelect = 0
UserForm_OptionButton1.Caption = "Single entry"
UserForm_OptionButton1.Value = True
UserForm_OptionButton2.Caption = "Multiple entries"
UserForm_OptionButton3.Caption = "Extended entries"
UserForm_ToggleButton1.Caption = "ListStyle - Plain"
UserForm_ToggleButton1.Value = True
UserForm_ToggleButton1.Width = 90
UserForm_ToggleButton1.Height = 30
End Sub
Sub UserForm_OptionButton1_Click()
UserForm_ListBox1.MultiSelect = 0
End Sub
Sub UserForm_OptionButton2_Click()
UserForm_ListBox1.MultiSelect = 1
End Sub
Sub UserForm_OptionButton3_Click()
UserForm_ListBox1.MultiSelect = 2
End Sub
Sub UserForm_ToggleButton1_Click()
If UserForm_ToggleButton1.Value = True Then
UserForm_ToggleButton1.Caption = "Plain ListStyle"
UserForm_ListBox1.ListStyle = 0
Else
UserForm_ToggleButton1.Caption = "OptionButton or CheckBox"
UserForm_ListBox1.ListStyle = 1
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
42
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