Label.ImageIndex 속성

정의

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

속성 값

ImageList 컨트롤(ImageList 속성에 할당됨)에서 이미지가 있는 위치를 나타내는 인덱스이며 0부터 시작합니다.A zero-based index that represents the position in the ImageList control (assigned to the ImageList property) where the image is located. 기본값은 -1입니다.The default is -1.

특성

예외

할당된 값이 ImageIndex 속성의 하한보다 작은 경우The value assigned is less than the lower bounds of the ImageIndex property.

예제

다음 코드 예제에서는 ImageListImageIndex 속성을 사용 하 여 3 차원 테두리와 이미지를 표시 하는 Label 컨트롤을 만드는 방법을 보여 줍니다.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. 예제 코드는 PreferredHeightPreferredWidth 속성을 사용 하 여 표시 되는 폼에서 Label 컨트롤의 크기를 적절히 조정 합니다.The example code uses the PreferredHeight and PreferredWidth properties to properly size the Label control on the form on which it is displayed. 이 예에서는 ImageList을 만들고 이름을 imageList1로 지정 하 고 두 개의 이미지를 로드 해야 합니다.This example requires that an ImageList has been created and named imageList1 and that it has loaded two images. 또한이 예제에서는 코드에 System.Drawing 네임 스페이스를 추가 하는 폼 안에 코드가 있어야 합니다.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

설명

ImageIndexImageList 속성은 Image 속성과 동시에 사용할 수 없습니다.The ImageIndex and the ImageList properties cannot be used at the same time as the Image property. ImageIndex 속성과 ImageList 속성을 사용 하 여 이미지를 표시 하는 경우 Image 속성이 자동으로 null로 설정 됩니다.When the ImageIndex property and ImageList properties are used to display an image, the Image property is automatically set to null.

적용 대상

추가 정보