Share via


Control.OnParentRightToLeftChanged(EventArgs) Metode

Definisi

RightToLeftChanged Menaikkan peristiwa saat RightToLeft nilai properti kontainer kontrol berubah.

protected:
 virtual void OnParentRightToLeftChanged(EventArgs ^ e);
protected virtual void OnParentRightToLeftChanged (EventArgs e);
abstract member OnParentRightToLeftChanged : EventArgs -> unit
override this.OnParentRightToLeftChanged : EventArgs -> unit
Protected Overridable Sub OnParentRightToLeftChanged (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 ini memiliki beberapa metode dengan pola On nama PropertyNameChanged yang menaikkan peristiwa PropertyNameChanged yang sesuai 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 Menaikkan Peristiwa.

Metode ini OnParentRightToLeftChanged 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 OnParentRightToLeftChanged(EventArgs) , pastikan untuk memanggil metode kelas OnParentRightToLeftChanged(EventArgs) dasar sehingga delegasi terdaftar menerima peristiwa tersebut.

Berlaku untuk

Lihat juga