Label.ImageIndex 속성

정의

Label에 표시된 이미지의 인덱스 값을 가져오거나 설정합니다.

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

속성 값

Int32

ImageList 컨트롤(ImageList 속성에 할당됨)에서 이미지가 있는 위치를 나타내는 인덱스이며 0부터 시작합니다. 기본값은 -1입니다.

특성

예외

value이 -1보다 작습니다.

예제

다음 코드 예제에서는 3 차원 테두리와 및 속성을 사용 하 여 표시 되는 이미지를 사용 하 여 컨트롤을 ImageList ImageIndex 만드는 Label 방법을 보여 줍니다. 또한 컨트롤에는 니모닉 문자가 지정된 캡션이 있습니다. 예제 코드는 및 PreferredWidth 속성을 사용하여 PreferredHeight 컨트롤이 표시되는 폼의 Label 컨트롤 크기를 적절하게 조정합니다. 이 예제에서는 imageList1을 ImageList 만들고 명명하고 두 개의 이미지를 로드해야 합니다. 또한 이 예제에서는 코드에 네임스페이스가 추가된 System.Drawing 양식 내에 코드가 있어야 합니다.

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

설명

ImageIndex 속성과 ImageList 속성을 동시에 Image 사용할 수 없습니다. ImageIndex 속성 및 ImageList 속성을 사용하여 이미지를 표시하면 속성이 Image 자동으로 .로 null설정됩니다.

ImageKeyImageIndex 은 상호 배타적입니다. 즉, 한 값이 설정된 경우 다른 값은 잘못된 값으로 설정되고 무시됩니다. 속성을 설정 ImageKey 하면 속성이 ImageIndex 자동으로 -1로 설정됩니다. 또는 속성을 ImageKey 설정하는 ImageIndex 경우 자동으로 빈 문자열("")로 설정됩니다.

속성 값이 ImageList 변경 null되면 속성은 ImageIndex 기본값 -1을 반환합니다. 그러나 할당된 ImageIndex 값은 내부적으로 유지되며 다른 ImageList 개체가 속성에 ImageList 할당될 때 사용됩니다. 속성에 ImageList 할당된 새 ImageList 속성 ImageList.ImageCollection.Count 값이 속성에 할당된 ImageIndex 값보다 작거나 같은 경우(컬렉션이 0부터 시작하는 인덱 ImageIndex 스인 경우) 속성 값이 속성 값보다 Count 작은 값으로 조정됩니다. 예를 들어 세 개의 이미지가 있고 ImageIndex 속성이 ImageList 2로 설정된 단추 컨트롤을 고려해 보세요. 두 개의 이미지만 있는 새 ImageList 이미지가 단추에 할당되면 값이 ImageIndex 1로 변경됩니다.

적용 대상

추가 정보