Control.OnParentChanged(EventArgs) 메서드

정의

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

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

매개 변수

e
EventArgs

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

예제

다음 코드 예제는 속성 값이 변경될 때 Text 실행되는 이벤트 발생 메서드입니다. Control 클래스에는 PropertyName 값이 변경되면 해당 PropertyNameChanged 이벤트를 발생시키는 Name 패턴 OnPropertyNameChanged이 있는 여러 메서드가 있습니다(PropertyName은 해당 속성의 이름을 나타남).

다음 코드 예제에서는 통화 데이터를 표시하는 파생 클래스의 TextBox 를 변경 ForeColor 합니다. 이 예제에서는 텍스트를 10진수로 변환하고 이 음수이 Color.Black 면 를 로, 숫자가 양수이면 으로 변경 ForeColorColor.Red 합니다. 이 예제에서는 클래스에서 파생되는 클래스가 TextBox 있어야 합니다.

protected:
   virtual void OnTextChanged( System::EventArgs^ e ) override
   {
      try
      {
         // Convert the text to a Double and determine
         // if it is a negative number.
         if ( Double::Parse( this->Text ) < 0 )
         {
            // If the number is negative, display it in Red.
            this->ForeColor = Color::Red;
         }
         else
         {
            // If the number is not negative, display it in Black.
            this->ForeColor = Color::Black;
         }
      }
      catch ( Exception^ ) 
      {
         // If there is an error, display the
         // text using the system colors.
         this->ForeColor = SystemColors::ControlText;
      }

      TextBox::OnTextChanged( e );
   }
protected override void OnTextChanged(System.EventArgs e)
{
   try
   {
      // Convert the text to a Double and determine
      // if it is a negative number.
      if(double.Parse(this.Text) < 0)
      {
         // If the number is negative, display it in Red.
         this.ForeColor = Color.Red;
      }
      else
      {
         // If the number is not negative, display it in Black.
         this.ForeColor = Color.Black;
      }
   }
   catch
   {
      // If there is an error, display the 
      // text using the system colors.
      this.ForeColor = SystemColors.ControlText;
   }
   
   base.OnTextChanged(e);
}
Protected Overrides Sub OnTextChanged(e As System.EventArgs)
   Try
      ' Convert the text to a Double and determine
      ' if it is a negative number.
      If Double.Parse(Me.Text) < 0 Then
         ' If the number is negative, display it in Red.
         Me.ForeColor = Color.Red
      Else
         ' If the number is not negative, display it in Black.
         Me.ForeColor = Color.Black
      End If
   Catch
      ' If there is an error, display the
      ' text using the system colors.
      Me.ForeColor = SystemColors.ControlText
   End Try

   MyBase.OnTextChanged(e)
End Sub

설명

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

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

상속자 참고

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

적용 대상

추가 정보