ToolStripItem.ImageKey 속성

정의

ImageList에 표시되는 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; }
[<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

속성 값

해당 이미지의 키를 나타내는 문자열입니다.

특성

예제

다음 코드 예제를 설정 하는 방법을 보여 줍니다는 ImageKey 속성입니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ToolStripItem 클래스입니다.

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

설명

ImageKeyImageIndex 는 상호 배타적입니다. 즉, 가 설정되면 다른 하나는 잘못된 값으로 설정되고 무시됩니다. 속성을 설정 ImageKey 하면 속성이 ImageIndex 자동으로 -1로 설정됩니다. 또는 속성을 설정 ImageIndex 하면 가 ImageKey 빈 문자열("")로 자동으로 설정됩니다.

합니다 Image, ImageAlignImageIndex, ImageKey, 및 ImageScaling 다양 한 이미지 처리와 관련 된 속성입니다. 이러한 속성을 직접 설정하거나 런타임 전용 ImageList 속성을 설정하여 컨트롤에서 이미지를 ToolStrip 사용합니다.

둘 다에서 속성의 상호 작용에 의해 결정 됩니다 이미지 크기 조정 ToolStripToolStripItem다음과 같이 합니다.

적용 대상