Label.ImageIndex Property

Definition

Obtiene o establece el valor de índice de la imagen que se muestra en Label.Gets or sets the index value of the image displayed on the Label.

public:
 property int ImageIndex { int get(); void set(int value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))]
public int ImageIndex { get; set; }
member this.ImageIndex : int with get, set
Public Property ImageIndex As Integer

Property Value

Int32

Índice basado en cero que representa la posición donde está ubicada la imagen en el control ImageList (asignado a la propiedad ImageList).A zero-based index that represents the position in the ImageList control (assigned to the ImageList property) where the image is located. El valor predeterminado es -1.The default is -1.

Attributes

Exceptions

El valor asignado es menor que los límites inferiores de la propiedad ImageIndex.The value assigned is less than the lower bounds of the ImageIndex property.

Examples

En el ejemplo de código siguiente se muestra cómo crear un control Label que tiene un borde tridimensional y una imagen que se muestra mediante las propiedades ImageList y ImageIndex.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. El control también tiene un título con un carácter mnemotécnico especificado.The control also has a caption with a mnemonic character specified. El código de ejemplo utiliza las propiedades PreferredHeight y PreferredWidth para ajustar correctamente el control Label en el formulario en el que se muestra.The example code uses the PreferredHeight and PreferredWidth properties to properly size the Label control on the form on which it is displayed. Este ejemplo requiere que se haya creado un ImageList y denominado imageList1 y que haya cargado dos imágenes.This example requires that an ImageList has been created and named imageList1 and that it has loaded two images. En el ejemplo también se requiere que el código esté dentro de un formulario que tenga el espacio de nombres System.Drawing agregado a su código.The example also requires that the code is within a form that has the System.Drawing namespace added to its code.

public:
   void CreateMyLabel()
   {
      // Create an instance of a Label.
      Label^ label1 = gcnew 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 = System::Drawing::Size( label1->PreferredWidth, label1->PreferredHeight );
      
      //...Code to add the control to the form...
   }
public void CreateMyLabel()
{
   // Create an instance of a Label.
   Label label1 = 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...
}

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

Remarks

Las propiedades ImageIndex y ImageList no se pueden usar al mismo tiempo que la propiedad Image.The ImageIndex and the ImageList properties cannot be used at the same time as the Image property. Cuando se usan las propiedades ImageIndex y ImageList para mostrar una imagen, la propiedad Image se establece automáticamente en null.When the ImageIndex property and ImageList properties are used to display an image, the Image property is automatically set to null.

Applies to

See also