ButtonBase.ImageIndex Property

 

Gets or sets the image list index value of the image displayed on the button control.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[<TypeConverterAttribute(typeof(ImageIndexConverter))>]
member ImageIndex : int with get, set

Property Value

Type: System.Int32

A zero-based index, which represents the image position in an ImageList. The default is -1.

Exception Condition
ArgumentOutOfRangeException

The assigned value is less than the lower bounds of the ImageIndex.

When the ImageIndex or ImageList properties are set, the Image property is set to its default value, null.

System_CAPS_noteNote

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.

The following code example uses the derived class, Button and sets the ImageList and ImageIndex properties. This code requires that an ImageList has been created and a minimum of one Image has been assigned to it. This code also requires that you have a bitmap image named MyBitMap.bmp stored in the C:\Graphics directory.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: