ComboBoxStyle 枚举

定义

指定 ComboBox 样式。

C#
public enum ComboBoxStyle
继承
ComboBoxStyle

字段

DropDown 1

通过单击下箭头指定显示列表,并指定文本部分可编辑。 这表示用户可以输入新的值,而不仅限于选择列表中现有的值。 使用此设置时,AppendAutoCompleteMode 值的作用与 SuggestAppend 值相同。 这是默认样式。

DropDownList 2

通过单击下箭头指定显示列表,并指定文本部分不可编辑。 这表示用户不能输入新的值。 只能选择列表中已有的值。 只有在 AutoCompleteModeSuggestSuggestAppend 时才会显示列表。

Simple 0

指定列表始终可见,并指定文本部分可编辑。 这表示用户可以输入新的值,而不仅限于选择列表中现有的值。

示例

下面的代码示例演示如何通过将属性设置为ComboBox.DropDownStyleComboBoxStyle值来初始化ComboBox控件。

C#
// Declare comboBox1 as a ComboBox.
internal System.Windows.Forms.ComboBox ComboBox1;

// This method initializes the combo box, adding a large string array
// but limiting the drop-down size to six rows so the combo box doesn't 
// cover other controls when it expands.
private void InitializeComboBox()
{
    this.ComboBox1 = new System.Windows.Forms.ComboBox();
    string[] employees = new string[]{"Hamilton, David", "Hensien, Kari",
            "Hammond, Maria", "Harris, Keith", "Henshaw, Jeff D.", 
            "Hanson, Mark", "Harnpadoungsataya, Sariya", 
            "Harrington, Mark", "Harris, Keith", "Hartwig, Doris", 
            "Harui, Roger", "Hassall, Mark", "Hasselberg, Jonas", 
            "Harnpadoungsataya, Sariya", "Henshaw, Jeff D.", 
            "Henshaw, Jeff D.", "Hensien, Kari", "Harris, Keith", 
            "Henshaw, Jeff D.", "Hensien, Kari", "Hasselberg, Jonas",
            "Harrington, Mark", "Hedlund, Magnus", "Hay, Jeff", 
            "Heidepriem, Brandon D."};

    ComboBox1.Items.AddRange(employees);
    this.ComboBox1.Location = new System.Drawing.Point(136, 32);
    this.ComboBox1.IntegralHeight = false;
    this.ComboBox1.MaxDropDownItems = 5;
    this.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
    this.ComboBox1.Name = "ComboBox1";
    this.ComboBox1.Size = new System.Drawing.Size(136, 81);
    this.ComboBox1.TabIndex = 0;
    this.Controls.Add(this.ComboBox1);
    
    // Associate the event-handling method with the 
    // SelectedIndexChanged event.
    this.ComboBox1.SelectedIndexChanged += 
        new System.EventHandler(ComboBox1_SelectedIndexChanged);
}

注解

DropDownStyle 属性指定列表是始终显示还是列表是否显示在下拉列表中。 该 DropDownStyle 属性还指定是否可以编辑文本部分。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7