ButtonBase.Image 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定顯示在按鈕控制上的影像。
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 並設定其一些常見屬性。 結果會是一個平面按鈕,左邊有文字,右邊有圖片。 此程式碼要求你在目錄中儲存C:\Graphics一個點MyBitMap.bmp陣圖影像,並且包含對命名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。