Share via


ButtonBase.Image Properti

Definisi

Mendapatkan atau mengatur gambar yang ditampilkan pada kontrol tombol.

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

Nilai Properti

yang Image ditampilkan pada kontrol tombol. Nilai defaultnya adalah null.

Contoh

Contoh kode berikut menggunakan kelas turunan, Button dan menetapkan beberapa properti umumnya. Hasilnya akan menjadi tombol datar dengan teks di sebelah kiri dan gambar di sebelah kanan. Kode ini mengharuskan Anda memiliki gambar bitmap bernama MyBitMap.bmp yang disimpan dalam C:\Graphics direktori, dan bahwa referensi ke System.Drawing namespace disertakan.

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

Keterangan

Image Ketika properti diatur, ImageList properti akan diatur ke null, dan ImageIndex properti akan diatur ke defaultnya, -1.

Catatan

FlatStyle Jika properti diatur ke FlatStyle.System, gambar apa pun yang ditetapkan ke Image properti tidak ditampilkan.

Berlaku untuk

Lihat juga