ButtonBase.ImageIndex 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.
Mendapatkan atau mengatur nilai indeks daftar gambar gambar yang ditampilkan pada kontrol tombol.
public:
property int ImageIndex { int get(); void set(int value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))]
public int ImageIndex { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))>]
member this.ImageIndex : int with get, set
Public Property ImageIndex As Integer
Nilai Properti
Indeks berbasis nol, yang mewakili posisi gambar dalam ImageList. Defaultnya adalah -1.
- Atribut
Pengecualian
value kurang dari -1.
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
ImageIndex Saat properti atau ImageList diatur, Image properti diatur ke nilai defaultnya, null.
ImageKey dan ImageIndex saling eksklusif, yang berarti jika satu diatur, yang lain diatur ke nilai yang tidak valid dan diabaikan. Jika Anda mengatur ImageKey properti , ImageIndex properti secara otomatis diatur ke -1. Atau, jika Anda mengatur ImageIndex properti , ImageKey secara otomatis diatur ke string kosong ("").
ImageList Jika nilai properti diubah menjadi null, ImageIndex properti mengembalikan nilai defaultnya, -1. Namun, nilai yang ditetapkan ImageIndex dipertahankan secara internal dan digunakan ketika objek 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 (untuk memperhitungkan koleksi menjadi 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.