Gets or sets the image list index value of the image displayed on the button control.
[Visual Basic] Public Property ImageIndex As Integer [C#] public int ImageIndex {get; set;} [C++] public: __property int get_ImageIndex(); public: __property void set_ImageIndex(int); [JScript] public function get ImageIndex() : int; public function set ImageIndex(int);
A zero-based index which represents the image position in an ImageList. The default is-1.
Exception Type | Condition |
---|---|
ArgumentException | 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, a null reference (in Visual Basic Nothing).
If the ImageList property changes and the ImageIndex property becomes greater than the upper bounds of the new ImageList, the ImageIndex property is set to its default value,-1.
The following example uses the derived class, Button and sets the ImageList and ImageIndex properties. This code assumes an ImageList has been instanciated and a minimum of one Image has been assigned to it.
[Visual Basic]
Private Sub MySub() ' Create a new resource. Dim resources As System.Resources.ResourceManager = _ New System.Resources.ResourceManager("Form1", "") ' Assign the ImageList to the button control. Button1.ImageList = ImageList1 ' Select the image from the ImageList (using the ImageIndex property). Button1.ImageIndex = 0 ' Get the image from the resource. Set Button1.Image = resources.GetObject("Button1.Image") End Sub
ButtonBase Class | ButtonBase Members | System.WinForms Namespace | ImageList