This documentation is archived and is not being maintained.

Label.ImageIndex Property

Gets or sets the index value of the image displayed on the Label.

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

<TypeConverterAttribute(GetType(ImageIndexConverter))> _
Public Property ImageIndex As Integer
Dim instance As Label 
Dim value As Integer 

value = instance.ImageIndex

instance.ImageIndex = value

Property Value

Type: System.Int32
A zero-based index that represents the position in the ImageList control (assigned to the ImageList property) where the image is located. The default is -1.


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

The ImageIndex and the ImageList properties cannot be used at the same time as the Image property. When the ImageIndex property and ImageList properties are used to display an image, the Image property is automatically set to Nothing.

The following code example demonstrates how to create a Label control that has a three-dimensional border and an image displayed using the ImageList and ImageIndex properties. The control also has a caption with a mnemonic character specified. The example code uses the PreferredHeight and PreferredWidth properties to properly size the Label control on the form on which it is displayed. This example requires that an ImageList has been created and named imageList1 and that it has loaded two images. The example also requires that the code is within a form that has the System.Drawing namespace added to its code.

Public Sub CreateMyLabel()
    ' Create an instance of a Label. 
    Dim label1 As New Label()

    ' Set the border to a three-dimensional border.
    label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    ' Set the ImageList to use for displaying an image.
    label1.ImageList = imageList1
    ' Use the second image in imageList1.
    label1.ImageIndex = 1
    ' Align the image to the top left corner.
    label1.ImageAlign = ContentAlignment.TopLeft

    ' Specify that the text can display mnemonic characters.
    label1.UseMnemonic = True 
    ' Set the text of the control and specify a mnemonic character.
    label1.Text = "First &Name:" 

    ' Set the size of the control based on the PreferredHeight and PreferredWidth values. 
    label1.Size = New Size(label1.PreferredWidth, label1.PreferredHeight)

    '...Code to add the control to the form... 
End Sub

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0