ButtonBase.ImageIndex Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Düğme denetiminde görüntülenen görüntünün görüntü listesi dizin değerini alır veya ayarlar.
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
Özellik Değeri
bir içindeki görüntü konumunu temsil eden sıfır tabanlı dizin ImageList. Varsayılan değer -1'dir.
- Öznitelikler
Özel durumlar
value -1'den küçüktür.
Örnekler
Aşağıdaki kod örneği türetilmiş sınıfını Button kullanır ve ve ImageIndex özelliklerini ayarlarImageList. Bu kod, bir ImageList oluşturulmasını ve en az bir tane Image atanmış olmasını gerektirir. Bu kod ayrıca dizininde C:\Graphics depolanan adlı MyBitMap.bmp bir bit eşlem görüntüye sahip olmanız gerekir.
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
Açıklamalar
ImageIndex veya ImageList özellikleri ayarlandığında, Image özelliği varsayılan değeri nullolan değerine ayarlanır.
ImageKey ve ImageIndex birbirini dışlar, yani biri ayarlanırsa, diğeri geçersiz bir değere ayarlanır ve yoksayılır. Özelliğini ayarlarsanız ImageKey , ImageIndex özelliği otomatik olarak -1 olarak ayarlanır. Alternatif olarak, özelliğini ayarlarsanız ImageIndex , ImageKey otomatik olarak boş bir dizeye ("") ayarlanır.
ImageList Özellik değeri olarak nullImageIndex değiştirilirse, özellik varsayılan değeri olan -1 değerini döndürür. Ancak, atanan ImageIndex değer dahili olarak tutulur ve özelliğe başka bir ImageList nesne atandığında ImageList kullanılır. Özelliğe atanan yeni ImageList özelliğinImageList, özelliğine atanan ImageIndex değerden küçük veya buna eşit bir ImageList.ImageCollection.Count özellik değeri varsa (koleksiyonun sıfır tabanlı bir dizin olduğunu hesaba katmak için), ImageIndex özellik değeri özellik değerinden Count bir küçük değere ayarlanır.
Örneğin, üç görüntüsü olan ImageList ve ImageIndex özelliği 2 olarak ayarlanmış bir düğme denetimi düşünün. Düğmeye yalnızca iki resim içeren bir yeni ImageList atanırsa, ImageIndex değer 1 olarak değişir.