ButtonBase.ImageList 屬性

定義

取得或設定含有按鈕控制項上所顯示的 ImageListImage

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

屬性值

ImageList

ImageList。 預設值是 null

範例

下列程式碼範例會使用衍生類別, Button 並設定 ImageListImageIndex 屬性。 此程式碼需要已建立 , ImageList 且至少已指派一個 Image 。 此程式碼也需要您有名為 MyBitMap.bmp 的點陣圖影像儲存在 C:\Graphics 目錄中。

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

備註

ImageList設定 或 ImageIndex 屬性時,會 Image 設定 null 屬性,這是其預設值。

注意

ImageList如果屬性值變更為 null ,則 ImageIndex 屬性會傳回其預設值 -1。 不過,指派 ImageIndex 的值會在內部保留,並在另一個 ImageList 指派給 ImageList 屬性時使用。 如果指派給 ImageList 屬性的新 ImageList 具有 ImageList.ImageCollection.Count 小於或等於指派給 ImageIndex 屬性的值減一 (,因為集合是以零起始的索引) , ImageIndex 屬性值會調整為小於屬性值的 Count 一個。 例如,假設有三個影像且屬性設定為 2 的 ImageIndex 按鈕控制項 ImageList 。 如果只有兩個影像的新 ImageList 指派給按鈕,則 ImageIndex 值會變更為 1。

適用於

另請參閱