Bagikan melalui


Control.ForeColor Properti

Definisi

Mendapatkan atau mengatur warna latar depan kontrol.

public:
 virtual property System::Drawing::Color ForeColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
public virtual System.Drawing.Color ForeColor { get; set; }
member this.ForeColor : System.Drawing.Color with get, set
Public Overridable Property ForeColor As Color

Nilai Properti

Latar depan Color kontrol. Defaultnya adalah nilai DefaultForeColor properti .

Contoh

Contoh kode berikut mengatur BackColor dan ForeColor kontrol ke warna sistem default. Kode secara rekursif memanggil dirinya sendiri jika kontrol memiliki kontrol anak. Contoh kode ini mengharuskan Anda memiliki Form setidaknya satu kontrol anak; namun, kontrol kontainer anak, seperti Panel atau GroupBox, dengan kontrol anaknya sendiri akan lebih baik menunjukkan rekursi.

   // Reset all the controls to the user's default Control color.
private:
   void ResetAllControlsBackColor( Control^ control )
   {
      control->BackColor = SystemColors::Control;
      control->ForeColor = SystemColors::ControlText;
      if ( control->HasChildren )
      {
         // Recursively call this method for each child control.
         IEnumerator^ myEnum = control->Controls->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            Control^ childControl = safe_cast<Control^>(myEnum->Current);
            ResetAllControlsBackColor( childControl );
         }
      }
   }
// Reset all the controls to the user's default Control color. 
private void ResetAllControlsBackColor(Control control)
{
   control.BackColor = SystemColors.Control;
   control.ForeColor = SystemColors.ControlText;
   if(control.HasChildren)
   {
      // Recursively call this method for each child control.
      foreach(Control childControl in control.Controls)
      {
         ResetAllControlsBackColor(childControl);
      }
   }
}
' Reset all the controls to the user's default Control color. 
Private Sub ResetAllControlsBackColor(control As Control)
   control.BackColor = SystemColors.Control
   control.ForeColor = SystemColors.ControlText
   If control.HasChildren Then
      ' Recursively call this method for each child control.
      Dim childControl As Control
      For Each childControl In  control.Controls
         ResetAllControlsBackColor(childControl)
      Next childControl
   End If
End Sub

Keterangan

Properti ForeColor adalah properti sekitar. Properti sekitar adalah properti kontrol yang, jika tidak diatur, diambil dari kontrol induk. Misalnya, akan Button memiliki yang sama BackColor dengan induknya Form secara default. Untuk informasi selengkapnya tentang properti sekitar, lihat AmbientProperties kelas atau Control gambaran umum kelas.

Catatan Bagi Inheritor

Saat mengambil alih ForeColor properti di kelas turunan, gunakan properti kelas ForeColor dasar untuk memperluas implementasi dasar. Jika tidak, Anda harus menyediakan semua implementasi. Anda tidak diharuskan untuk mengambil alih properti get dan set aksesor ForeColor ; Anda hanya dapat mengambil alih satu jika diperlukan.

Berlaku untuk

Lihat juga