Label.ImageList 속성

정의

ImageList 컨트롤에 표시할 이미지를 포함하는 Label를 가져오거나 설정합니다.Gets or sets the ImageList that contains the images to display in the Label control.

public:
 property System::Windows::Forms::ImageList ^ ImageList { System::Windows::Forms::ImageList ^ get(); void set(System::Windows::Forms::ImageList ^ value); };
public System.Windows.Forms.ImageList ImageList { get; set; }
member this.ImageList : System.Windows.Forms.ImageList with get, set
Public Property ImageList As ImageList

속성 값

ImageList 개체의 컬렉션을 저장하는 Image입니다.An ImageList that stores the collection of Image objects. 기본값은 null입니다.The default value is null.

예제

다음 코드 예제에서는 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 set to null.

참고

ImageList 다른 곳에서 참조 되는 경우 Label 가비지 수집 되지 않습니다.The Label will not be garbage collected if its ImageList is still referenced elsewhere. 효율적인 가비지 수집을 사용 하려면 LabelImageList 속성을 null로 설정 합니다.Set the ImageList property of the Label to null to enable efficient garbage collection.

적용 대상

추가 정보