Table of contents

ListStyle、MultiSelect 属性示例ListStyle, MultiSelect Properties Example

office 365 dev account|上次更新日期: 2018/3/13
2 参与人员

下面的示例使用ListStyle多重选择属性来控制列表框的外观。用户为ListStyle使用切换按钮中选择一个值并选择用于多重选择值中的一个选项按钮列表框的外观相应的变化在列表框中的选择行为。The following example uses the ListStyle and MultiSelect properties to control the appearance of a ListBox. The user chooses a value for ListStyle using the ToggleButton and chooses an OptionButton for one of the MultiSelect values. The appearance of the ListBox changes accordingly, as well as the selection behavior within the ListBox.

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

  • 列表框一个名为 ListBox1。A ListBox named ListBox1.

  • 名为 Label1 的标签A Label named Label1.

  • 名为 OptionButton1 至 OptionButton3 的三个数值调节钮控件。Three OptionButton controls named OptionButton1 through OptionButton3.

  • 切换按钮命名为 ToggleButton1。A ToggleButton named ToggleButton1.

Private Sub UserForm_Initialize() 
 Dim i As Integer 

 For i = 1 To 8 
 ListBox1.AddItem "Choice" &; (ListBox1.ListCount + 1) 
 Next i 

 Label1.Caption = "MultiSelect Choices" 
 Label1.AutoSize = True 

 ListBox1.MultiSelect = fmMultiSelectSingle 
 OptionButton1.Caption = "Single entry" 
 OptionButton1.Value = True 
 OptionButton2.Caption = "Multiple entries" 
 OptionButton3.Caption = "Extended entries" 

 ToggleButton1.Caption = "ListStyle - Plain" 
 ToggleButton1.Value = True 
 ToggleButton1.Width = 90 
 ToggleButton1.Height = 30 
End Sub 

Private Sub OptionButton1_Click() 
 ListBox1.MultiSelect = fmMultiSelectSingle 
End Sub 

Private Sub OptionButton2_Click() 
 ListBox1.MultiSelect = fmMultiSelectMulti 
End Sub 

Private Sub OptionButton3_Click() 
 ListBox1.MultiSelect = fmMultiSelectExtended 
End Sub 

Private Sub ToggleButton1_Click() 
 If ToggleButton1.Value = True Then 
 ToggleButton1.Caption = "Plain ListStyle" 
 ListBox1.ListStyle = fmListStylePlain 
 ToggleButton1.Caption = "OptionButton " _ 
 &; "or CheckBox" 
 ListBox1.ListStyle = fmListStyleOption 
 End If 
End Sub
© 2018 Microsoft