Label.ImageList Свойство

Определение

Возвращает или задает свойство ImageList, содержащее изображения, отображаемые в элементе управления Label.

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; }
public System.Windows.Forms.ImageList? ImageList { get; set; }
member this.ImageList : System.Windows.Forms.ImageList with get, set
Public Property ImageList As ImageList

Значение свойства

ImageList

В свойстве ImageList хранится коллекция объектов Image. Значение по умолчанию — null.

Примеры

В следующем примере кода показано, как создать Label элемент управления с трехмерной границей и изображением, отображаемым с помощью ImageList и ImageIndex свойств. Элемент управления также содержит заголовок с указанным символом mnemonic. В примере кода используются PreferredHeight свойства и PreferredWidth свойства для правильного Label размера элемента управления в форме, в которой она отображается. В этом примере требуется, чтобы ImageList был создан и именован imageList1, а также что он загрузил два образа. В примере также требуется, чтобы код находится в форме, 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

Комментарии

ImageList Свойства ImageIndex нельзя использовать одновременно со свойствомImage. ImageIndex Если свойство и ImageList свойства используются для отображения изображения, Image свойству nullприсваивается значение .

Примечание

Сборка Label мусора не будет собираться, если она ImageList по-прежнему ссылается в другом месте. ImageList Задайте свойство для null включения эффективной сборки Label мусора.

Применяется к

См. также раздел