ButtonBase.ImageList 属性

定义

获取或设置包含按钮控件上显示的 ImageListImage

C#
public System.Windows.Forms.ImageList ImageList { get; set; }
C#
public System.Windows.Forms.ImageList? ImageList { get; set; }

属性值

ImageList

ImageList。 默认值是 null

示例

下面的代码示例使用派生类, Button 并设置 ImageListImageIndex 属性。 此代码要求已创建一个 ImageList 代码,并且至少已为其分配一个 Image 代码。 此代码还要求你具有一个名为 MyBitMap.bmp 存储在目录中的 C:\Graphics 位图图像。

C#
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;
 }

注解

ImageList设置或ImageIndex属性时,将设置nullImage属性,即其默认值。

备注

ImageList如果属性值更改为null,则ImageIndex属性将返回其默认值 -1。 但是,分配 ImageIndex 的值在内部保留,并在将另一个 ImageList 值分配给 ImageList 该属性时使用。 如果分配给ImageList该属性的新ImageList属性的ImageList.ImageCollection.Count属性值小于或等于分配给ImageIndex属性的值减去一个 (,因为集合是从零开始的索引) ,则ImageIndex属性值将调整为小于属性值的Count一个。 例如,请考虑一个按钮控件,该 ImageList 控件具有三个图像,其 ImageIndex 属性设置为 2。 如果只有两个 ImageList 图像的新图像分配给该按钮,该值 ImageIndex 将更改为 1。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅