Locked、DropButtonStyle、ShowDropButtonWhen 属性示例Locked, DropButtonStyle, ShowDropButtonWhen properties example

下面的示例演示可以为 ComboBoxTextBox 中的下拉箭头指定的不同符号。The following example demonstrates the different symbols that you can specify for a drop-down arrow in a ComboBox or TextBox.

在本示例中,用户从 ComboBox 中选择下拉箭头样式。In this example, the user chooses a drop-down arrow style from a ComboBox. 本示例还使用**Locked** 属性。This example also uses the Locked property.

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

  • 一个名为"ComboBox1"的 ComboBoxA ComboBox named ComboBox1.
  • 一个名为"Label1"的 LabelA Label named Label1.
  • 一个放置在"Label1"下的名为"TextBox1"的 TextBoxA TextBox named TextBox1 placed beneath Label1.
Private Sub ComboBox1_Click() 
 ComboBox1.DropButtonStyle = ComboBox1.Value 
 TextBox1.DropButtonStyle = ComboBox1.Value 
End Sub 
 
Private Sub UserForm_Initialize() 
 ComboBox1.ColumnCount = 2 
 ComboBox1.BoundColumn = 2 
 ComboBox1.TextColumn = 1 
 
 ComboBox1.AddItem "Blank Button" 
 ComboBox1.List(0, 1) = 0 
 ComboBox1.AddItem "Down Arrow" 
 ComboBox1.List(1, 1) = 1 
 ComboBox1.AddItem "Ellipsis" 
 ComboBox1.List(2, 1) = 2 
 ComboBox1.AddItem "Underscore" 
 ComboBox1.List(3, 1) = 3 
 
 ComboBox1.Value = 0 
 
 TextBox1.Text = "TextBox1" 
 TextBox1.ShowDropButtonWhen = fmShowDropButtonWhenAlways 
 TextBox1.Locked = True 
 
 Label1.Caption = "TheDropButton also " _ 
 & "applies to a TextBox." 
 Label1.AutoSize = True 
 Label1.WordWrap = False 
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.