通过


ComboBox.OnSelectionChangeCommitted(EventArgs) 方法

定义

引发 SelectionChangeCommitted 事件。

protected:
 virtual void OnSelectionChangeCommitted(EventArgs ^ e);
protected virtual void OnSelectionChangeCommitted(EventArgs e);
abstract member OnSelectionChangeCommitted : EventArgs -> unit
override this.OnSelectionChangeCommitted : EventArgs -> unit
Protected Overridable Sub OnSelectionChangeCommitted (e As EventArgs)

参数

e
EventArgs

包含事件数据的一个 EventArgs

示例

下面的代码示例使用 SelectionChangeCommitted 事件和 SelectionLength 属性根据用户选择和提交的内容更改文本框的长度。

void comboBox1_SelectionChangeCommitted( Object^ sender, EventArgs^ /*e*/ )
{
   ComboBox^ senderComboBox = dynamic_cast<ComboBox^>(sender);
   
   // Change the length of the text box depending on what the user has 
   // selected and committed using the SelectionLength property.
   if ( senderComboBox->SelectionLength > 0 )
   {
       textbox1->Width = 
           senderComboBox->SelectedItem->ToString()->Length * 
           ((int)this->textbox1->Font->SizeInPoints);
       textbox1->Text = senderComboBox->SelectedItem->ToString();				
   }
}
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{

    ComboBox senderComboBox = (ComboBox) sender;
  
    // Change the length of the text box depending on what the user has 
    // selected and committed using the SelectionLength property.
    if (senderComboBox.SelectionLength > 0)
    {
        textbox1.Width = 
            senderComboBox.SelectedItem.ToString().Length *
            ((int) this.textbox1.Font.SizeInPoints);
        textbox1.Text = senderComboBox.SelectedItem.ToString();
    }
}
Private Sub comboBox1_SelectionChangeCommitted(ByVal sender _
As Object, ByVal e As EventArgs) _
Handles comboBox1.SelectionChangeCommitted

    Dim senderComboBox As ComboBox = CType(sender, ComboBox)

    ' Change the length of the text box depending on what the user has 
    ' selected and committed using the SelectionLength property.
    If (senderComboBox.SelectionLength > 0) Then
        textbox1.Width = _
            senderComboBox.SelectedItem.ToString().Length() * _
            CType(Me.textbox1.Font.SizeInPoints, Integer)
        textbox1.Text = senderComboBox.SelectedItem.ToString()
    End If
End Sub

注解

SelectionChangeCommitted仅在用户更改组合框选择或设置SelectedIndex组合框时引发。 但是,根据配置方式以及用户更改所选项的方式 ComboBoxSelectionChangeCommitted 可能不会引发该事件。 或者,可以处理该 SelectedIndexChanged事件,但请注意,无论索引是以编程方式更改还是由用户更改,都会发生此事件。

引发事件会通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件

该方法 OnSelectionChangeCommitted 还允许派生类在不附加委托的情况下处理事件。 这是处理派生类中的事件的首选技术。

继承者说明

在派生类中重写 OnSelectionChangeCommitted(EventArgs) 时,请务必调用基类的方法,以便已注册的 OnSelectionChangeCommitted(EventArgs) 委托接收事件。

适用于