Label.ImageList 属性

获取或设置包含要在 Label 控件中显示的图像的 ImageList

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property ImageList As ImageList
用法
Dim instance As Label
Dim value As ImageList

value = instance.ImageList

instance.ImageList = value
public ImageList ImageList { get; set; }
public:
property ImageList^ ImageList {
    ImageList^ get ();
    void set (ImageList^ value);
}
/** @property */
public ImageList get_ImageList ()

/** @property */
public void set_ImageList (ImageList value)
public function get ImageList () : ImageList

public function set ImageList (value : ImageList)

属性值

ImageList,它存储 Image 对象集合。默认值为 空引用(在 Visual Basic 中为 Nothing)。

备注

ImageIndexImageList 属性不能同时用作 Image 属性。当 ImageIndex 属性和 ImageList 属性用于显示图像时,Image 属性被设置为 空引用(在 Visual Basic 中为 Nothing)。

提示

如果其他地方仍在引用 LabelImageList,则不会对 Label 进行垃圾回收。将 LabelImageList 属性设置为 空引用(在 Visual Basic 中为 Nothing) 可启用有效的垃圾回收。

示例

下面的代码示例演示如何使用 ImageListImageIndex 属性创建一个 Label 控件,该控件显示一个三维边框和一幅图像。该控件也有一个指定助记键字符的标题。此示例代码使用 PreferredHeightPreferredWidth 属性来适当地调整 Label 控件在显示它的窗体上的大小。此示例要求已创建一个名为 imageList1ImageList,并且它已加载两幅图像。此示例还要求该代码在一个窗体内,该窗体已将 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 属性
Label.ImageIndex 属性
ImageList 类