ToolStripItem.ImageIndex Property

Definition

Gets or sets the index value of the image that is displayed on the item.

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

Property Value

The zero-based index of the image in the ImageList that is displayed for the item. The default is -1, signifying that the image list is empty.

Attributes

Exceptions

value is less than -1.

Remarks

ImageKey and ImageIndex are mutually exclusive, meaning if one is set, the other is set to an invalid value and ignored. If you set the ImageKey property, the ImageIndex property is automatically set to -1. Alternatively, if you set the ImageIndex property, the ImageKey is automatically set to an empty string ("").

The Image, ImageAlign, ImageIndex, ImageKey, and ImageScaling properties pertain to various aspects of image handling. Use images in ToolStrip controls by setting these properties directly or by setting the run-time-only ImageList property.

Image scaling is determined by the interaction of properties in both ToolStrip and ToolStripItem, as follows:

If the ImageList property value is changed to null, the ImageIndex property returns its default value, -1. However, the assigned ImageIndex value is retained internally and used when another ImageList object is assigned to the ImageList property. If the new ImageList assigned to the ImageList property has an ImageList.ImageCollection.Count property value that is less than or equal to the value assigned to the ImageIndex property minus one (to account for the collection being a zero-based index), the ImageIndex property value is adjusted to one less than the Count property value. For example, consider a button control whose ImageList has three images and whose ImageIndex property is set to 2. If a new ImageList that has only two images is assigned to the button, the ImageIndex value changes to 1.

Applies to