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 オブジェクトのコレクションを格納する Image。 既定値は null です。

次のコード例では、 プロパティと ImageIndex プロパティをLabel使用して表示される 3 次元の境界線と画像を含むコントロールを作成する方法をImageList示します。 コントロールには、ニーモニック文字が指定されたキャプションもあります。 このコード例では、 PreferredHeight プロパティと PreferredWidth プロパティを使用して、 Label 表示されるフォームのコントロールのサイズを適切に設定します。 この例では、 が ImageList 作成され、imageList1 という名前が付けられ、2 つのイメージが読み込まれている必要があります。 この例では、コードが、コードに名前空間が追加された 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使用してイメージを表示する場合、 Image プロパティは にnull設定ImageListされます。

注意

Labelが他の場所で引き続き参照されている場合ImageList、 はガベージ コレクションされません。 効率的なガベージ コレクションを ImageList 有効にするには、 の Label プロパティを に null 設定します。

適用対象

こちらもご覧ください