ButtonBase.ImageList Właściwość

Definicja

Pobiera lub ustawia ImageList kontrolkę wyświetlaną Image na kontrolce przycisku.

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

Wartość właściwości

ImageList

Element ImageList. Wartość domyślna to null.

Przykłady

Poniższy przykład kodu używa klasy Button pochodnej i ustawia ImageList właściwości i ImageIndex . Ten kod wymaga utworzenia elementu ImageList i przypisano do niego co najmniej jeden Image kod. Ten kod wymaga również obrazu mapy bitowej o nazwie MyBitMap.bmp przechowywanej C:\Graphics w katalogu.

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

Uwagi

ImageList Gdy właściwość or ImageIndex jest ustawionaImage, właściwość jest ustawiona null, która jest jego wartością domyślną.

Uwaga

ImageList Jeśli wartość właściwości zostanie zmieniona na null, ImageIndex właściwość zwróci jego wartość domyślną, -1. Jednak przypisana ImageIndex wartość jest zachowywana wewnętrznie i używana, gdy inna ImageList jest przypisana ImageList do właściwości. Jeśli nowa ImageList przypisana do ImageList właściwości ma ImageList.ImageCollection.Count wartość właściwości mniejszą niż lub równą wartości przypisanej do ImageIndex właściwości minus jeden (ponieważ kolekcja jest indeksem opartym na zerowym), ImageIndex wartość właściwości jest dostosowywana do wartości mniejszej niż Count wartość właściwości. Rozważmy na przykład kontrolkę przycisku z ImageList trzema obrazami i właściwością ImageIndex ustawioną na 2. Jeśli nowy ImageList , który ma tylko dwa obrazy, zostanie przypisany do przycisku, ImageIndex wartość zmieni się na 1.

Dotyczy

Zobacz też