ButtonBase.Image 屬性

定義

取得或設定按鈕控制項上顯示的影像。

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

屬性值

按鈕控制項上所顯示的 Image。 預設值是 null

範例

下列程式碼範例會使用衍生類別, Button 並設定其一些通用屬性。 結果會是一個平面按鈕,其中包含左邊的文字,以及右邊的影像。 此程式碼需要您有一個名為 MyBitMap.bmp 的點陣圖影像儲存在 C:\Graphics 目錄中,且包含命名空間的 System.Drawing 參考。

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。

注意

FlatStyle如果 屬性設定 FlatStyle.System 為 ,則不會顯示指派給 Image 屬性的任何影像。

適用於

另請參閱