ButtonBase.Image 属性

定义

获取或设置显示在按钮控件上的图像。

C#
public System.Drawing.Image Image { get; set; }
C#
public System.Drawing.Image? Image { get; set; }

属性值

Image

按钮控件上显示的 Image。 默认值是 null

示例

下面的代码示例使用派生类, Button 并设置其一些常见属性。 结果将是一个平面按钮,其中包含左侧的文本和右侧的图像。 此代码要求你具有一个名为 MyBitMap.bmp 存储在目录中的 C:\Graphics 位图图像,并且包含对命名空间的 System.Drawing 引用。

C#
private void SetMyButtonProperties()
 {
    // Assign an image to the button.
    button1.Image = Image.FromFile("C:\\Graphics\\MyBitmap.bmp");
    // Align the image and text on the button.
    button1.ImageAlign = ContentAlignment.MiddleRight;    
    button1.TextAlign = ContentAlignment.MiddleLeft;
    // Give the button a flat appearance.
    button1.FlatStyle = FlatStyle.Flat;
 }

注解

Image设置属性后,该ImageList属性将设置为 null,并将ImageIndex该属性设置为其默认值 -1。

备注

FlatStyle如果该属性设置为 FlatStyle.System,则不会显示分配给该Image属性的任何图像。

适用于

产品 版本
.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

另请参阅