Control.OnFontChanged(EventArgs) Yöntem

Tanım

Olayı tetikler FontChanged .

protected:
 virtual void OnFontChanged(EventArgs ^ e);
protected virtual void OnFontChanged (EventArgs e);
abstract member OnFontChanged : EventArgs -> unit
override this.OnFontChanged : EventArgs -> unit
Protected Overridable Sub OnFontChanged (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, OnFontChanged 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ıldığınızda OnFontChanged(EventArgs) , kayıtlı temsilcilerin olayı alması için temel sınıfın OnFontChanged(EventArgs) yöntemini çağırdığınızdan emin olun.

Şunlara uygulanır

Ayrıca bkz.