Control.OnTabStopChanged(EventArgs) Metode

Definisi

Memunculkan kejadian TabStopChanged.

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

Parameter

e
EventArgs

Yang EventArgs berisi data peristiwa.

Contoh

Contoh kode berikut adalah metode penggalangan peristiwa yang dijalankan saat Text nilai properti berubah. Kelas Control memiliki beberapa metode dengan pola On nama PropertyNameChanged yang menaikkan peristiwa PropertyNameChanged terkait saat nilai PropertyName berubah (PropertyName mewakili nama properti yang sesuai).

Contoh kode berikut mengubah ForeColor kelas turunan yang TextBox menampilkan data mata uang. Contoh mengonversi teks menjadi angka desimal dan mengubah menjadi ForeColorColor.Red jika angka negatif dan menjadi Color.Black jika angka positif. Contoh ini mengharuskan Anda memiliki kelas yang berasal dari TextBox kelas .

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

Keterangan

Menaikkan peristiwa memanggil penanganan aktivitas melalui delegasi. Untuk informasi selengkapnya, lihat Menangani dan Meningkatkan Peristiwa.

Metode ini OnTabStopChanged juga memungkinkan kelas turunan untuk menangani peristiwa tanpa melampirkan delegasi. Ini adalah teknik yang disukai untuk menangani peristiwa di kelas turunan.

Catatan Bagi Inheritor

Saat mengambil alih di kelas turunan OnTabStopChanged(EventArgs) , pastikan untuk memanggil metode kelas OnTabStopChanged(EventArgs) dasar sehingga delegasi terdaftar menerima peristiwa tersebut.

Berlaku untuk

Lihat juga