ButtonBase.Image 属性

定义

获取或设置显示在按钮控件上的图像。Gets or sets the image that is displayed on a button control.

public:
 property System::Drawing::Image ^ Image { System::Drawing::Image ^ get(); void set(System::Drawing::Image ^ value); };
public System.Drawing.Image Image { get; set; }
member this.Image : System.Drawing.Image with get, set
Public Property Image As Image

属性值

按钮控件上显示的 ImageThe Image displayed on the button control. 默认值是 nullThe default value is null.

示例

下面的代码示例使用派生类,Button 并设置其一些公共属性。The following code example uses the derived class, Button and sets some of its common properties. 结果将是一个平面按钮,其左侧有文本,右侧有一个图像。The result will be a flat button with text on the left and an image on the right. 此代码要求在 C:\Graphics 目录中存储名为 MyBitMap.bmp 的位图映像,并包含对 System.Drawing 命名空间的引用。This code requires that you have a bitmap image named MyBitMap.bmp stored in the C:\Graphics directory, and that a reference to the System.Drawing namespace is included.

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;
   }
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;
 }
 
Private Sub 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
End Sub

注解

设置 Image 属性时,ImageList 属性将设置为 nullImageIndex 属性将设置为其默认值-1。When the Image property is set, the ImageList property will be set to null, and the ImageIndex property will be set to its default, -1.

备注

如果 FlatStyle 属性设置为 FlatStyle.System,则不显示分配给 Image 属性的任何图像。If the FlatStyle property is set to FlatStyle.System, any images assigned to the Image property are not displayed.

适用于

另请参阅