ComboBox.DropDown 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於顯示 ComboBox 的下拉部分時。
public:
event EventHandler ^ DropDown;
public event EventHandler DropDown;
public event EventHandler? DropDown;
member this.DropDown : EventHandler
Public Custom Event DropDown As EventHandler
事件類型
範例
下列程式碼範例示範如何藉由設定 text 屬性,以及使用 AddRange 方法來填入 ComboBox 來初始化 ComboBox 控制項。 它也會示範如何處理 DropDown 事件。 若要執行此範例,請在表單中貼上下列程式碼,並在表單的建構函式或 Load 事件中呼叫 InitializeComboBox
方法。
internal:
// Declare ComboBox1
System::Windows::Forms::ComboBox^ ComboBox1;
private:
// Initialize ComboBox1.
void InitializeComboBox()
{
this->ComboBox1 = gcnew ComboBox;
this->ComboBox1->Location = System::Drawing::Point( 128, 48 );
this->ComboBox1->Name = "ComboBox1";
this->ComboBox1->Size = System::Drawing::Size( 100, 21 );
this->ComboBox1->TabIndex = 0;
this->ComboBox1->Text = "Typical";
array<String^>^ installs = {"Typical","Compact","Custom"};
ComboBox1->Items->AddRange( installs );
this->Controls->Add( this->ComboBox1 );
// Hook up the event handler.
this->ComboBox1->DropDown += gcnew System::EventHandler(
this, &Form1::ComboBox1_DropDown );
}
// Handles the ComboBox1 DropDown event. If the user expands the
// drop-down box, a message box will appear, recommending the
// typical installation.
void ComboBox1_DropDown( Object^ sender, System::EventArgs^ e )
{
MessageBox::Show( "Typical installation is strongly recommended.",
"Install information", MessageBoxButtons::OK,
MessageBoxIcon::Information );
}
// Declare ComboBox1.
internal System.Windows.Forms.ComboBox ComboBox1;
// Initialize ComboBox1.
private void InitializeComboBox()
{
this.ComboBox1 = new ComboBox();
this.ComboBox1.Location = new System.Drawing.Point(128, 48);
this.ComboBox1.Name = "ComboBox1";
this.ComboBox1.Size = new System.Drawing.Size(100, 21);
this.ComboBox1.TabIndex = 0;
this.ComboBox1.Text = "Typical";
string[] installs = new string[]{"Typical", "Compact", "Custom"};
ComboBox1.Items.AddRange(installs);
this.Controls.Add(this.ComboBox1);
// Hook up the event handler.
this.ComboBox1.DropDown +=
new System.EventHandler(ComboBox1_DropDown);
}
// Handles the ComboBox1 DropDown event. If the user expands the
// drop-down box, a message box will appear, recommending the
// typical installation.
private void ComboBox1_DropDown(object sender, System.EventArgs e)
{
MessageBox.Show("Typical installation is strongly recommended.",
"Install information", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
' Declare ComboBox1.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
' Initialize ComboBox1.
Private Sub InitializeComboBox()
Me.ComboBox1 = New ComboBox
Me.ComboBox1.Location = New System.Drawing.Point(128, 48)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(100, 21)
Me.ComboBox1.TabIndex = 0
Me.ComboBox1.Text = "Typical"
Dim installs() As String = New String() _
{"Typical", "Compact", "Custom"}
ComboBox1.Items.AddRange(installs)
Me.Controls.Add(Me.ComboBox1)
End Sub
' Handles the ComboBox1 DropDown event. If the user expands the
' drop-down box, a message box will appear, recommending the
' typical installation.
Private Sub ComboBox1_DropDown _
(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles ComboBox1.DropDown
MessageBox.Show("Typical installation is strongly recommended.", _
"Install information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
備註
如需處理事件的詳細資訊,請參閱 處理和引發事件。