Control.OnParentBackColorChanged(EventArgs) Yöntem

Tanım

Denetimin BackColorChanged kapsayıcısının BackColor özellik değeri değiştiğinde olayı tetikler.

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

Parametreler

e
EventArgs

EventArgs Olay verilerini içeren bir.

Örnekler

Aşağıdaki kod örneği, özellik değeri değiştiğinde Text yürütülen bir olay oluşturma yöntemidir. sınıfı, Control PropertyName değeri değiştiğinde ilgili PropertyNameChanged olayını oluşturan PropertyNameChanged adlı On birkaç yönteme sahiptir (PropertyName, karşılık gelen özelliğin adını temsil eder).

Aşağıdaki kod örneği, para birimi verilerini görüntüleyen türetilmiş bir TextBox sınıfın türünü değiştirirForeColor. Örnek, metni ondalık sayıya dönüştürür ve sayı negatifse ve Color.Black sayı pozitifse olarak değiştirir.ForeColorColor.Red Bu örnek, sınıfından türetilen TextBox bir sınıfınız olmasını gerektirir.

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

Açıklamalar

Olay bildirmek, bir temsilci yoluyla olay işleyicisini çağırır. Daha fazla bilgi için bkz. Olayları İşleme ve Oluşturma.

yöntemi, OnParentBackColorChanged türetilmiş sınıfların temsilci eklemeden olayı işlemesini de sağlar. Bu, türetilmiş bir sınıftaki olayı işlemek için tercih edilen tekniktir.

Devralanlara Notlar

Türetilmiş bir sınıfta geçersiz kıldığınızda OnParentBackColorChanged(EventArgs) , kayıtlı temsilcilerin olayı alması için temel sınıfın OnParentBackColorChanged(EventArgs) yöntemini çağırdığınızdan emin olun.

Şunlara uygulanır

Ayrıca bkz.