ToolStripItem.ImageKey ToolStripItem.ImageKey ToolStripItem.ImageKey ToolStripItem.ImageKey Property

Definição

Obtém ou define o acessador de chave para a imagem na ImageList que é exibido em um ToolStripItem.Gets or sets the key accessor for the image in the ImageList that is displayed on a ToolStripItem.

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; }
member this.ImageKey : string with get, set
Public Property ImageKey As String

Valor da propriedade

Uma cadeia de caracteres que representa a chave da imagem.A string representing the key of the image.

Exemplos

O exemplo de código a seguir demonstra como definir ImageKey a propriedade.The following code example demonstrates how to set the ImageKey property. Este exemplo de código faz parte de um exemplo maior fornecido para ToolStripItem a classe.This code example is part of a larger example provided for the ToolStripItem class.

// 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

Comentários

A ImageIndex propriedade especifica a posição da imagem na lista de imagens.The ImageIndex property specifies the position of the image in the image list. A ImageKey propriedade especifica a própria imagem.The ImageKey property specifies the image itself.

As Imagepropriedades ImageAlign, ,ImageIndex ,ImageKeye pertencemImageScaling a vários aspectos da manipulação de imagens.The Image, ImageAlign, ImageIndex, ImageKey, and ImageScaling properties pertain to various aspects of image handling. Use imagens em ToolStrip controles definindo essas propriedades diretamente ou definindo a propriedade somente ImageList de tempo de execução.Use images in ToolStrip controls by setting these properties directly or by setting the run-time-only ImageList property.

O dimensionamento de imagem é determinado pela interação das propriedades ToolStrip no ToolStripIteme no, da seguinte maneira:Image scaling is determined by the interaction of properties in both ToolStrip and ToolStripItem, as follows:

Aplica-se a