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

屬性值

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. 此程式碼會要求您有一個名為的點陣圖影像 MyBitMap.bmp 儲存在 C:\Graphics 目錄中,而且 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 屬性會設定為 null ,且 ImageIndex 屬性會設定為預設值-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.

適用於

另請參閱