ToolStripItem.ImageKey プロパティ


ImageList に表示されている ToolStripItem で、イメージのキー アクセサーを取得または設定します。Gets or sets the key accessor for the image in the ImageList that is displayed on a ToolStripItem.

 property System::String ^ ImageKey { System::String ^ get(); void set(System::String ^ value); };
public string ImageKey { get; set; }
member this.ImageKey : string with get, set
Public Property ImageKey As String


イメージのキーを表す文字列。A string representing the key of the image.


ImageKeyプロパティを設定する方法を次のコード例に示します。The following code example demonstrates how to set the ImageKey property. このコード例は、 ToolStripItemクラスに対して提供される大規模な例の一部です。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


プロパティImageIndexは、イメージリスト内のイメージの位置を指定します。The ImageIndex property specifies the position of the image in the image list. プロパティImageKeyは、イメージ自体を指定します。The ImageKey property specifies the image itself.

ImageImageAlign、 、ImageKey、およびの各プロパティは、イメージ処理のさまざまな側面に関連します。ImageScaling ImageIndexThe Image, ImageAlign, ImageIndex, ImageKey, and ImageScaling properties pertain to various aspects of image handling. コントロールでToolStrip画像を使用するには、これらのプロパティを直接設定するか、 ImageList実行時のみのプロパティを設定します。Use images in ToolStrip controls by setting these properties directly or by setting the run-time-only ImageList property.

イメージのスケーリングは、次のように、とToolStrip ToolStripItemの両方のプロパティの相互作用によって決定されます。Image scaling is determined by the interaction of properties in both ToolStrip and ToolStripItem, as follows: