ButtonBase.ImageList 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
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。 預設值為 null。
範例
以下程式碼範例使用導出類別, Button 並設定 ImageList 和 ImageIndex 屬性。 此代碼要求已建立且 ImageList 至少指派一個 Image 。 這段程式碼也要求你在目錄中儲存C:\Graphics一個命名的MyBitMap.bmp點陣圖映像檔。
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 屬性值小一。 例如,考慮一個按鈕控制項,其 ImageList 有三個圖片,屬性 ImageIndex 設為 2。 如果指派一個只有兩張圖片的新按鈕ImageListImageIndex,值會變為 1。