DomainUpDown.OnSelectedItemChanged(Object, EventArgs) 메서드

정의

SelectedItemChanged 이벤트를 발생시킵니다.

protected:
 void OnSelectedItemChanged(System::Object ^ source, EventArgs ^ e);
protected void OnSelectedItemChanged (object source, EventArgs e);
protected void OnSelectedItemChanged (object? source, EventArgs e);
member this.OnSelectedItemChanged : obj * EventArgs -> unit
Protected Sub OnSelectedItemChanged (source As Object, e As EventArgs)

매개 변수

source
Object

이벤트 소스입니다.

e
EventArgs

이벤트 데이터가 포함된 EventArgs입니다.

예제

다음 코드 예제에서는 컨트롤을 DomainUpDown 만들고 초기화합니다. 이 예제에서는 일부 속성을 설정하고 스핀 상자에 표시할 문자열 컬렉션을 만들 수 있습니다(업다운 컨트롤이라고도 함). 코드는 , CheckBoxButtonTextBox양식에서 인스턴스화되었다고 가정합니다. 이 예제에서는 또한 라는 32 비트 부호 있는 정수로 선언 된 클래스 수준에서 멤버 변수 있다고 가정 myCounter합니다. 텍스트 상자에 문자열을 입력 하 고 추가 Items 단추를 클릭할 때 컬렉션입니다. 검사 상자를 클릭하면 속성을 토글 Sorted 하고 스핀 상자의 항목 컬렉션에서 차이를 확인할 수 있습니다.

protected:
   DomainUpDown^ domainUpDown1;

private:
   void MySub()
   {
      // Create and initialize the DomainUpDown control.
      domainUpDown1 = gcnew System::Windows::Forms::DomainUpDown;
      
      // Add the DomainUpDown control to the form.
      Controls->Add( domainUpDown1 );
   }

   void button1_Click( System::Object^ sender,
     System::EventArgs^ e )
   {
      // Add the text box contents and initial location in the collection
      // to the DomainUpDown control.
      domainUpDown1->Items->Add( String::Concat(
         (textBox1->Text->Trim()), " - ", myCounter.ToString() ) );
      
      // Increment the counter variable.
      myCounter = myCounter + 1;
      
      // Clear the TextBox.
      textBox1->Text = "";
   }

   void checkBox1_Click( Object^ sender, EventArgs^ e )
   {
      // If Sorted is set to true, set it to false; 
      // otherwise set it to true.
      if ( domainUpDown1->Sorted )
      {
         domainUpDown1->Sorted = false;
      }
      else
      {
         domainUpDown1->Sorted = true;
      }
   }

   void domainUpDown1_SelectedItemChanged( Object^ sender, EventArgs^ e )
   {
      // Display the SelectedIndex and SelectedItem property values in a MessageBox.
      MessageBox::Show( String::Concat( "SelectedIndex: ",
      domainUpDown1->SelectedIndex.ToString(), "\n", "SelectedItem: ",
      domainUpDown1->SelectedItem->ToString() ) );
   }
protected DomainUpDown domainUpDown1;

private void MySub()
 {
    // Create and initialize the DomainUpDown control.
    domainUpDown1 = new System.Windows.Forms.DomainUpDown();
    
    // Add the DomainUpDown control to the form.
    Controls.Add(domainUpDown1);
 }
 
 private void button1_Click(System.Object sender, 
                           System.EventArgs e)
 {   
    // Add the text box contents and initial location in the collection
    // to the DomainUpDown control.
    domainUpDown1.Items.Add((textBox1.Text.Trim()) + " - " + myCounter);
    
    // Increment the counter variable.
    myCounter = myCounter + 1;
 
    // Clear the TextBox.
    textBox1.Text = "";
 }
 
 private void checkBox1_Click(System.Object sender, 
                             System.EventArgs e)
 {
    // If Sorted is set to true, set it to false; 
    // otherwise set it to true.
    if (domainUpDown1.Sorted)
    {
       domainUpDown1.Sorted = false;
    }
    else
    {
       domainUpDown1.Sorted = true;
    }
 }
 
 private void domainUpDown1_SelectedItemChanged(System.Object sender, 
                                               System.EventArgs e)
 {
    // Display the SelectedIndex and SelectedItem property values in a MessageBox.
    MessageBox.Show("SelectedIndex: " + domainUpDown1.SelectedIndex.ToString() 
       + "\n" + "SelectedItem: " + domainUpDown1.SelectedItem.ToString());
 }
Protected domainUpDown1 As DomainUpDown


Private Sub MySub()
    ' Create and initialize the DomainUpDown control.
    domainUpDown1 = New System.Windows.Forms.DomainUpDown()
    
    ' Add the DomainUpDown control to the form.
    Controls.Add(domainUpDown1)
End Sub


Private Sub button1_Click(sender As System.Object, e As System.EventArgs)
    ' Add the text box contents and initial location in the collection
    ' to the DomainUpDown control.
    domainUpDown1.Items.Add((textBox1.Text.Trim() & " - " & myCounter))
    
    ' Increment the counter variable.
    myCounter = myCounter + 1
    
    ' Clear the TextBox.
    textBox1.Text = ""
End Sub


Private Sub checkBox1_Click(sender As System.Object, e As System.EventArgs)
    ' If Sorted is set to true, set it to false; 
    ' otherwise set it to true.
    If domainUpDown1.Sorted Then
        domainUpDown1.Sorted = False
    Else
        domainUpDown1.Sorted = True
    End If
End Sub


Private Sub domainUpDown1_SelectedItemChanged _
    (sender As System.Object, e As System.EventArgs)
    
    ' Display the SelectedIndex and SelectedItem property values in a MessageBox.
    MessageBox.Show(("SelectedIndex: " & domainUpDown1.SelectedIndex.ToString() & _
        ControlChars.Cr & "SelectedItem: " & domainUpDown1.SelectedItem.ToString()))
End Sub

설명

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다. 자세한 내용은 이벤트 처리 및 발생합니다.

또한 OnSelectedItemChanged 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.

상속자 참고

재정의 하는 경우 OnSelectedItemChanged(Object, EventArgs) 파생된 클래스에서 호출 해야 기본 클래스 OnSelectedItemChanged(Object, EventArgs) 메서드 등록 된 대리자가 이벤트를 받도록 합니다.

적용 대상

추가 정보