次の方法で共有


Label.ImageList プロパティ

Label コントロールに表示するイメージを保持する ImageList を取得または設定します。

Public Property ImageList As ImageList
[C#]
public ImageList ImageList {get; set;}
[C++]
public: __property ImageList* get_ImageList();public: __property void set_ImageList(ImageList*);
[JScript]
public function get ImageList() : ImageList;public function set ImageList(ImageList);

プロパティ値

Image オブジェクトのコレクションを格納する ImageList 。既定値は null 参照 (Visual Basic では Nothing) です。

解説

ImageIndex プロパティと ImageList プロパティは、 Image プロパティと同時には使用できません。イメージを表示するために ImageIndex プロパティと ImageList プロパティを使用すると、 Image プロパティは自動的に null 参照 (Visual Basic では Nothing) に設定されます。

使用例

3 次元の輪郭と、 ImageList プロパティおよび ImageIndex プロパティを使用して表示するイメージを持つ Label コントロールの作成方法の例を次に示します。このコントロールには、ニーモニック文字を指定したキャプションも表示されます。このコードの例では、 PreferredHeight プロパティと PreferredWidth プロパティを使用して、表示するフォーム上の Label コントロールのサイズを適切に設定します。また、この例では、 imageList1 という名前の ImageList が作成され、2 つのイメージが読み込まれていることを前提にしています。このコードがフォーム内にあり、そのフォームのコードに 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


[C#] 
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...
}


[C++] 
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 = S"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...
 }
 

[JScript] 
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 NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Label クラス | Label メンバ | System.Windows.Forms 名前空間 | Image | ImageAlign | ImageIndex | ImageList