ToolStripItem.ImageKey Właściwość

Definicja

Pobiera lub ustawia metodę dostępu klucza dla obrazu wyświetlanego ImageList w ToolStripItemobiekcie .

public:
 property System::String ^ ImageKey { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Browsable(false)]
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageKeyConverter))]
[System.Windows.Forms.RelatedImageList("Owner.ImageList")]
public string ImageKey { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageKeyConverter))>]
[<System.Windows.Forms.RelatedImageList("Owner.ImageList")>]
member this.ImageKey : string with get, set
Public Property ImageKey As String

Wartość właściwości

Ciąg reprezentujący klucz obrazu.

Atrybuty

Przykłady

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

// This utility method creates a RolloverItem 
// and adds it to a ToolStrip control.
private RolloverItem CreateRolloverItem(
    ToolStrip owningToolStrip,
    string txt,
    Font f,
    string imgKey,
    TextImageRelation tir,
    string backImgKey)
{
    RolloverItem item = new RolloverItem();

    item.Alignment = ToolStripItemAlignment.Left;
    item.AllowDrop = false;
    item.AutoSize = true;

    item.BackgroundImage = owningToolStrip.ImageList.Images[backImgKey];
    item.BackgroundImageLayout = ImageLayout.Center;
    item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
    item.DoubleClickEnabled = true;
    item.Enabled = true;
    item.Font = f;

    // These assignments are equivalent. Each assigns an
    // image from the owning toolstrip's image list.
    item.ImageKey = imgKey;
    //item.Image = owningToolStrip.ImageList.Images[infoIconKey];
    //item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
    item.ImageScaling = ToolStripItemImageScaling.None;

    item.Owner = owningToolStrip;
    item.Padding = new Padding(2);
    item.Text = txt;
    item.TextAlign = ContentAlignment.MiddleLeft;
    item.TextDirection = ToolStripTextDirection.Horizontal;
    item.TextImageRelation = tir;

    return item;
}
' This utility method creates a RolloverItem 
' and adds it to a ToolStrip control.
 Private Function CreateRolloverItem( _
 ByVal owningToolStrip As ToolStrip, _
 ByVal txt As String, _
 ByVal f As Font, _
 ByVal imgKey As String, _
 ByVal tir As TextImageRelation, _
 ByVal backImgKey As String) As RolloverItem

     Dim item As New RolloverItem()

     item.Alignment = ToolStripItemAlignment.Left
     item.AllowDrop = False
     item.AutoSize = True

     item.BackgroundImage = owningToolStrip.ImageList.Images(backImgKey)
     item.BackgroundImageLayout = ImageLayout.Center
     item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
     item.DoubleClickEnabled = True
     item.Enabled = True
     item.Font = f

     ' These assignments are equivalent. Each assigns an
     ' image from the owning toolstrip's image list.
     item.ImageKey = imgKey
     'item.Image = owningToolStrip.ImageList.Images[infoIconKey];
     'item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
     item.ImageScaling = ToolStripItemImageScaling.None

     item.Owner = owningToolStrip
     item.Padding = New Padding(2)
     item.Text = txt
     item.TextAlign = ContentAlignment.MiddleLeft
     item.TextDirection = ToolStripTextDirection.Horizontal
     item.TextImageRelation = tir

     Return item
 End Function

Uwagi

ImageKey i ImageIndex wzajemnie wykluczają się, co oznacza, że jeśli jeden jest ustawiony, drugi jest ustawiony na nieprawidłową wartość i ignorowany. Jeśli ustawisz ImageKey właściwość , właściwość zostanie automatycznie ustawiona ImageIndex na -1. Alternatywnie, jeśli ustawisz ImageIndex właściwość , ImageKey właściwość zostanie automatycznie ustawiona na pusty ciąg ("").

Właściwości Image, , ImageIndexImageAlign, ImageKeyi ImageScaling odnoszą się do różnych aspektów obsługi obrazów. Użyj obrazów w ToolStrip kontrolkach, ustawiając te właściwości bezpośrednio lub ustawiając właściwość tylko ImageList w czasie wykonywania.

Skalowanie obrazów jest określane przez interakcję właściwości w obiektach ToolStrip i ToolStripItemw następujący sposób:

Dotyczy