ButtonBase.Image Właściwość

Definicja

Pobiera lub ustawia obraz wyświetlany w kontrolce przycisku.

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

Wartość właściwości

Wyświetlany Image na kontrolce przycisku. Wartość domyślna to null.

Przykłady

Poniższy przykład kodu używa klasy Button pochodnej i ustawia niektóre z jego typowych właściwości. Wynik będzie płaskim przyciskiem z tekstem po lewej stronie i obrazem po prawej stronie. Ten kod wymaga obrazu mapy bitowej o nazwie MyBitMap.bmp przechowywanej C:\Graphics w katalogu i dołączeniu odwołania do System.Drawing przestrzeni nazw.

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

Uwagi

Po ustawieniu ImageImageList właściwości właściwość zostanie ustawiona na null, a ImageIndex właściwość zostanie ustawiona na domyślną wartość -1.

Uwaga

Jeśli właściwość jest ustawiona FlatStyle na FlatStyle.System, wszystkie obrazy przypisane do Image właściwości nie są wyświetlane.

Dotyczy

Zobacz też