ボタン コントロールに表示される Image を保持している 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);
プロパティ値
ImageList 。既定値は null 参照 (Visual Basic では Nothing) です。
解説
ImageList プロパティまたは ImageIndex プロパティが設定されている場合は、 Image プロパティが既定値の null 参照 (Visual Basic では Nothing) に設定されます。
メモ ImageList プロパティ値が null 参照 (Nothing) に変更された場合、 ImageIndex プロパティは既定値 -1 を返します。ただし、代入された ImageIndex 値は内部で保持され、この ImageList プロパティに別の ImageList が割り当てられたときに使用されます。 ImageList プロパティに割り当てられた新しい ImageList の ImageCollection.Count プロパティ値が、 ImageIndex プロパティに代入されている値から 1 を引いた値以下の場合 (コレクションが 0 から始まるインデックス番号であるため)、 ImageIndex プロパティ値は Count プロパティ値より 1 小さい値に調整されます。たとえば、3 つのイメージがある ImageList を持ち、 ImageIndex プロパティが 2 に設定されているボタン コントロールがあるとします。このボタンに、イメージが 2 つしかない新しい ImageList を割り当てると、 ImageIndex 値は 1 に変更されます。
使用例
派生クラス Button を使用して、 ImageList プロパティと ImageIndex プロパティを設定する例を次に示します。このコードは、 ImageList が作成され、そこに Image が 1 つ以上割り当てられていることを前提にしています。また、 C:\Graphics
ディレクトリに MyBitMap.bmp
という名前のビットマップ イメージが格納されていることも前提にしています。
Private Sub AddMyImage()
' Assign an image to the ImageList.
ImageList1.Images.Add(Image.FromFile("C:\Graphics\MyBitmap.bmp"))
' Assign the ImageList to the button control.
button1.ImageList = ImageList1
' Select the image from the ImageList (using the ImageIndex property).
button1.ImageIndex = 0
End Sub 'AddMyImage
[C#]
private void AddMyImage()
{
// Assign an image to the ImageList.
ImageList1.Images.Add(Image.FromFile("C:\\Graphics\\MyBitmap.bmp"));
// Assign the ImageList to the button control.
button1.ImageList = ImageList1;
// Select the image from the ImageList (using the ImageIndex property).
button1.ImageIndex = 0;
}
[C++]
private:
void AddMyImage() {
// Assign an image to the imageList.
imageList1->Images->Add(Image::FromFile(S"C:\\Graphics\\MyBitmap.bmp"));
// Assign the imageList to the button control.
button1->ImageList = imageList1;
// Select the image from the ImageList (using the ImageIndex property).
button1->ImageIndex = 0;
}
[JScript]
private function AddMyImage()
{
// Assign an image to the ImageList.
ImageList1 = new ImageList;
ImageList1.Images.Add(Image.FromFile("C:\\Graphics\\MyBitmap.bmp"));
// Assign the ImageList to the button control.
button1.ImageList = ImageList1;
// Select the image from the ImageList (using the ImageIndex property).
button1.ImageIndex = 0;
}
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
ButtonBase クラス | ButtonBase メンバ | System.Windows.Forms 名前空間 | Image | ImageIndex