Control.BackColor Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur warna latar belakang untuk kontrol.
public:
virtual property System::Drawing::Color BackColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
public virtual System.Drawing.Color BackColor { get; set; }
member this.BackColor : System.Drawing.Color with get, set
Public Overridable Property BackColor As Color
Nilai Properti
Color yang mewakili warna latar belakang kontrol. Defaultnya adalah nilai DefaultBackColor 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 BackColor tidak mendukung warna transparan kecuali SupportsTransparentBackColor nilai System.Windows.Forms.ControlStyles diatur ke true.
Properti BackColor 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 BackColor properti di kelas turunan, gunakan properti kelas BackColor dasar untuk memperluas implementasi dasar. Jika tidak, Anda harus menyediakan semua implementasi. Anda tidak diharuskan untuk mengambil alih properti get dan set aksesor BackColor ; Anda hanya dapat mengambil alih satu jika diperlukan.