ComboBoxStyle 列舉

定義

指定 ComboBox 樣式。

public enum class ComboBoxStyle
public enum ComboBoxStyle
type ComboBoxStyle = 
Public Enum ComboBoxStyle
繼承
ComboBoxStyle

欄位

DropDown 1

指定清單是以按一下向下鍵的方式顯示,以及指定文字部分為可編輯。 這表示使用者可以在清單中輸入新的值,並且不限於選取現有的值。 使用這個設定時,AppendAutoCompleteMode 值的運作方式與 SuggestAppend 值相同。 這是預設樣式。

DropDownList 2

指定清單是以按一下向下鍵的方式顯示,以及指定文字部分為不可編輯。 這表示使用者無法輸入新的值, 只能選取清單中現有的值。 只有 AutoCompleteModeSuggestSuggestAppend 時,才顯示這個清單。

Simple 0

指定一律顯示清單,以及指定文字部分為可編輯。 這表示使用者可以在清單中輸入新的值,並且不限於選取現有的值。

範例

下列程式碼範例示範如何將 屬性設定 ComboBox.DropDownStyleComboBoxStyle 值來初始化 ComboBox 控制項。

   // Declare comboBox1 as a ComboBox.
internal:
   System::Windows::Forms::ComboBox^ ComboBox1;

private:
   // 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.
   void InitializeComboBox()
   {
      this->ComboBox1 = gcnew System::Windows::Forms::ComboBox;
      array<String^>^ employees = {"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 = 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 = 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 +=
         gcnew System::EventHandler( this, &Form1::ComboBox1_SelectedIndexChanged );
   }
// 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);
}

' Declare comboBox1 as a ComboBox.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

' 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 Sub InitializeComboBox()
    Me.ComboBox1 = New System.Windows.Forms.ComboBox
    Dim employees() As String = 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)
    Me.ComboBox1.Location = New System.Drawing.Point(136, 32)
    Me.ComboBox1.IntegralHeight = False
    Me.ComboBox1.MaxDropDownItems = 5
    Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
    Me.ComboBox1.Name = "ComboBox1"
    Me.ComboBox1.Size = New System.Drawing.Size(136, 81)
    Me.ComboBox1.TabIndex = 0
    Me.Controls.Add(Me.ComboBox1)
End Sub

備註

屬性 DropDownStyle 會指定一律顯示清單,還是清單是否顯示在下拉式清單中。 屬性 DropDownStyle 也會指定是否可以編輯文字部分。

適用於