다음을 통해 공유


Label.ImageIndex 속성

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

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<LocalizableAttribute(True)> _
Public Property ImageIndex As Integer
‘사용 방법
Dim instance As Label
Dim value As Integer

value = instance.ImageIndex

instance.ImageIndex = value
[LocalizableAttribute(true)] 
public int ImageIndex { get; set; }
[LocalizableAttribute(true)] 
public:
property int ImageIndex {
    int get ();
    void set (int value);
}
/** @property */
public int get_ImageIndex ()

/** @property */
public void set_ImageIndex (int value)
public function get ImageIndex () : int

public function set ImageIndex (value : int)

속성 값

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

예외

예외 형식 조건

ArgumentOutOfRangeException

할당된 값이 ImageIndex 속성의 하한보다 작은 경우

설명

ImageIndexImageList 속성은 Image 속성과 동시에 사용할 수 없습니다. ImageIndex 속성과 ImageList 속성을 사용하여 이미지를 표시하면 Image 속성이 Null 참조(Visual Basic의 경우 Nothing)로 자동 설정됩니다.

예제

다음 코드 예제에서는 ImageListImageIndex 속성으로 표시되는 3차원 테두리 및 이미지가 있는 Label 컨트롤을 만드는 방법을 보여 줍니다. 또한 이 컨트롤에는 지정된 니모닉 문자를 사용하는 캡션이 있습니다. 이 예제 코드에서는 PreferredHeightPreferredWidth 속성을 사용하여 Label 컨트롤이 표시된 폼 위에서 해당 컨트롤의 크기를 적절히 조정합니다. 이 예제를 실행하려면 imageList1이라는 이름으로 ImageList가 만들어져 있고 여기에 두 개의 이미지가 로드되어 있어야 합니다. 또한 이 예제를 실행하려면 해당 코드에 System.Drawing 네임스페이스가 추가된 폼 안에 코드가 있어야 합니다.

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
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:
   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.set_BorderStyle(System.Windows.Forms.BorderStyle.Fixed3D);
    // Set the ImageList to use for displaying an image.
    label1.set_ImageList(imageList1);
    // Use the second image in imageList1.
    label1.set_ImageIndex(1);
    // Align the image to the top left corner.
    label1.set_ImageAlign(ContentAlignment.TopLeft);
    // Specify that the text can display mnemonic characters.
    label1.set_UseMnemonic(true);
    // Set the text of the control and specify a mnemonic character.
    label1.set_Text("First &Name:");
    /* Set the size of the control based on the PreferredHeight
       and PreferredWidth values. */
    label1.set_Size(new Size(label1.get_PreferredWidth(), 
        label1.get_PreferredHeight()));
    //...Code to add the control to the form...
} //CreateMyLabel 
public function CreateMyLabel()
{
   // Create an instance of a Label.
   var label1 : Label = 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 System.Drawing.Size (label1.PreferredWidth, label1.PreferredHeight);

   //...Code to add the control to the form...
}

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

Label 클래스
Label 멤버
System.Windows.Forms 네임스페이스
Label.Image 속성
Label.ImageAlign 속성
ImageList