ButtonBase.ImageList Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
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
Nilai Properti
Sebuah ImageList. Nilai defaultnya adalah null.
Contoh
Contoh kode berikut menggunakan kelas turunan, Button dan mengatur ImageList properti dan ImageIndex . Kode ini mengharuskan telah ImageList dibuat dan minimal satu Image telah ditetapkan untuk itu. Kode ini juga mengharuskan Anda memiliki gambar bitmap bernama MyBitMap.bmp yang disimpan di C:\Graphics direktori.
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;
}
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;
}
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
Keterangan
ImageList Ketika properti atau ImageIndex diatur, Image properti diatur null, yang merupakan nilai defaultnya.
Nota
ImageList Jika nilai properti diubah menjadi null, ImageIndex properti mengembalikan nilai defaultnya, -1. Namun, nilai yang ditetapkan ImageIndex dipertahankan secara internal dan digunakan ketika nilai lain ImageList ditetapkan ke ImageList properti . Jika yang baru ImageList ditetapkan ke ImageList properti memiliki ImageList.ImageCollection.Count nilai properti yang kurang dari atau sama dengan nilai yang ditetapkan ke ImageIndex properti dikurangi satu (karena koleksi adalah indeks berbasis nol), ImageIndex nilai properti disesuaikan menjadi satu kurang dari Count nilai properti. Misalnya, pertimbangkan kontrol tombol yang ImageList memiliki tiga gambar dan yang propertinya ImageIndex diatur ke 2. Jika baru ImageList yang hanya memiliki dua gambar ditetapkan ke tombol , nilai berubah ImageIndex menjadi 1.