Control.OnDockChanged(EventArgs) Yöntem

Tanım

Olayı tetikler DockChanged .

protected:
 virtual void OnDockChanged(EventArgs ^ e);
protected virtual void OnDockChanged (EventArgs e);
abstract member OnDockChanged : EventArgs -> unit
override this.OnDockChanged : EventArgs -> unit
Protected Overridable Sub OnDockChanged (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 yürütülen Text bir olay oluşturma yöntemidir. sınıfı, Control PropertyName değeri değiştiğinde karşılık gelen PropertyNameChanged olayını oluşturan PropertyNameChanged adlı On çeşitli yöntemlere 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 Color.Black ve 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, OnDockChanged türetilmiş sınıfların bir temsilci eklemeden olayı işlemesine de izin verir. 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ılma OnDockChanged(EventArgs) sırasında, kayıtlı temsilcilerin olayı alması için temel sınıfın OnDockChanged(EventArgs) yöntemini çağırdığınızdan emin olun.

Şunlara uygulanır

Ayrıca bkz.