Control.OnParentEnabledChanged(EventArgs) Método

Definição

Gera o evento EnabledChanged quando o valor da propriedade Enabled de alterações do contêiner do controle muda.

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

Parâmetros

e
EventArgs

Um EventArgs que contém os dados do evento.

Exemplos

O exemplo de código a seguir é um método de geração de eventos executado quando o valor da Text propriedade é alterado. A Control classe tem vários métodos com o padrão Onde nome PropertyNameChanged que geram o evento PropertyNameChanged correspondente quando o valor PropertyName é alterado (PropertyName representa o nome da propriedade correspondente).

O exemplo de código a seguir altera o ForeColor de uma TextBox classe derivada exibindo dados de moeda. O exemplo converte o texto em um número decimal e altera o ForeColor para Color.Red se o número for negativo e para Color.Black se o número for positivo. Este exemplo exige que você tenha uma classe derivada da TextBox classe .

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

Comentários

A geração de um evento invoca o manipulador de eventos por meio de um delegado. Para obter mais informações, consulte Manipulando e levantando eventos.

O OnParentEnabledChanged método também permite que classes derivadas manipulem o evento sem anexar um delegado. Essa é a técnica preferencial para lidar com o evento em uma classe derivada.

Notas aos Herdeiros

Ao substituir OnParentEnabledChanged(EventArgs) em uma classe derivada, chame o método da OnParentEnabledChanged(EventArgs) classe base para que os delegados registrados recebam o evento.

Aplica-se a

Confira também