ButtonBase.ImageList Eigenschaft
Definition
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; }
member this.ImageList : System.Windows.Forms.ImageList with get, set
Public Property ImageList As ImageList
Eigenschaftswert
Beispiele
Im folgenden Codebeispiel wird Button die abgeleitete-Klasse verwendet und die-Eigenschaft und die ImageList - ImageIndex Eigenschaft festgelegt.The following code example uses the derived class, Button and sets the ImageList and ImageIndex properties. Dieser Code erfordert, dass ImageList eine erstellt und mindestens Image eine zugewiesen wurde.This code requires that an ImageList has been created and a minimum of one Image has been assigned to it. Dieser Code erfordert auch, dass Sie über ein Bitmapbild MyBitMap.bmp
mit dem C:\Graphics
Namen verfügen, das im Verzeichnis gespeichert ist.This code also requires that you have a bitmap image named MyBitMap.bmp
stored in the C:\Graphics
directory.
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
Hinweise
Wenn die ImageList - ImageIndex Eigenschaft oder die-Eigenschaft Image festgelegt ist null
, wird die-Eigenschaft festgelegt. Dies ist der Standardwert.When the ImageList or ImageIndex property is set, the Image property is set null
, which is its default value.
Hinweis
Wenn der ImageList -Eigenschafts Wert in null
geändert wird ImageIndex , gibt die-Eigenschaft den Standardwert-1 zurück.If the ImageList property value is changed to null
, the ImageIndex property returns its default value, -1. Der zugewiesene ImageIndex Wert wird jedoch intern beibehalten und verwendet, wenn der ImageList ImageList Eigenschaft ein anderer zugewiesen wird.However, the assigned ImageIndex value is retained internally and used when another ImageList is assigned to the ImageList property. Wenn das neue ImageList , das der ImageList Eigenschaft zugewiesen ist ImageList.ImageCollection.Count , einen Eigenschafts Wert hat, der kleiner oder gleich dem Wert ist ImageIndex , der der Eigenschaft minus eins zugewiesen ist (da die Auflistung ein NULL basierter Index ImageIndex ist), wird der der Eigenschafts Wert wird auf einen Wert kleiner Count als der Eigenschafts Wert angepasst.If the new ImageList assigned to the ImageList property has an ImageList.ImageCollection.Count property value that is less than or equal to the value assigned to the ImageIndex property minus one (because the collection is a zero-based index), the ImageIndex property value is adjusted to one less than the Count property value. Angenommen, Sie haben ein Schaltflächen- ImageList Steuerelement, dessen über ImageIndex drei Bilder verfügt und dessen-Eigenschaft auf 2 festgelegt ist.For example, consider a button control whose ImageList has three images and whose ImageIndex property is set to 2. Wenn eine neue ImageList , die nur über zwei Bilder verfügt, der Schaltfläche zugewiesen ImageIndex wird, ändert sich der Wert in 1.If a new ImageList that has only two images is assigned to the button, the ImageIndex value changes to 1.