Bagikan melalui


ToolStripItem.BackColor Properti

Definisi

Mendapatkan atau mengatur warna latar belakang untuk item.

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 item. Defaultnya adalah nilai DefaultBackColor properti .

Contoh

Contoh kode berikut menunjukkan cara menggunakan properti untuk penyajian BackColor kustom. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ToolStripItem kelas .

protected override void OnRenderItemImage(
    ToolStripItemImageRenderEventArgs e)
{
    base.OnRenderItemImage(e);

    RolloverItem item = e.Item as RolloverItem;

    // If the ToolSTripItem is of type RolloverItem, 
    // perform custom rendering for the image.
    if (item != null)
    {
        if (item.Clicked)
        {
            // The item is in the clicked state, so 
            // draw the image as usual.
            e.Graphics.DrawImage(
                e.Image,
                e.ImageRectangle.X,
                e.ImageRectangle.Y);
        }
        else
        {
            // In the unclicked state, gray out the image.
            ControlPaint.DrawImageDisabled(
                e.Graphics,
                e.Image,
                e.ImageRectangle.X,
                e.ImageRectangle.Y,
                item.BackColor);
        }
    }
}
Protected Overrides Sub OnRenderItemImage(ByVal e As ToolStripItemImageRenderEventArgs)
    MyBase.OnRenderItemImage(e)

    Dim item As RolloverItem = CType(e.Item, RolloverItem)

    ' If the ToolSTripItem is of type RolloverItem, 
    ' perform custom rendering for the image.
    If (item IsNot Nothing) Then
        If item.Clicked Then
            ' The item is in the clicked state, so 
            ' draw the image as usual.
            e.Graphics.DrawImage(e.Image, e.ImageRectangle.X, e.ImageRectangle.Y)
        Else
            ' In the unclicked state, gray out the image.
            ControlPaint.DrawImageDisabled(e.Graphics, e.Image, e.ImageRectangle.X, e.ImageRectangle.Y, item.BackColor)
        End If
    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, memiliki Button 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.

Berlaku untuk