ToolStripItem.BackColor Właściwość

Definicja

Pobiera lub ustawia kolor tła elementu.

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

Wartość właściwości

Element Color reprezentujący kolor tła elementu. Wartość domyślna to wartość DefaultBackColor właściwości .

Przykłady

W poniższym przykładzie kodu pokazano, jak używać BackColor właściwości do renderowania niestandardowego. Ten przykład kodu jest częścią większego przykładu udostępnionego ToolStripItem dla klasy .

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

Uwagi

Właściwość BackColor nie obsługuje przezroczystych kolorów, chyba że SupportsTransparentBackColor wartość parametru System.Windows.Forms.ControlStyles jest ustawiona na true.

Obiekt BackColor jest właściwością otoczenia. Właściwość otoczenia jest właściwością kontrolki, która, jeśli nie jest ustawiona, jest pobierana z kontrolki nadrzędnej. Na przykład obiekt Button ma to samo, BackColor co jego element nadrzędny Form domyślnie. Aby uzyskać więcej informacji na temat właściwości otoczenia, zobacz AmbientProperties omówienie klasy lub Control klasy.

Uwagi dotyczące dziedziczenia

Podczas zastępowania BackColor właściwości w klasie pochodnej użyj właściwości klasy BackColor bazowej, aby rozszerzyć implementację podstawową. W przeciwnym razie należy podać całą implementację. Nie jest wymagane zastąpienie zarówno metod dostępuBackColor, jak get i set właściwości ; w razie potrzeby można zastąpić tylko jedną.

Dotyczy