Export (0) Print
Expand All

ButtonBase.Image Property

Gets or sets the image that is displayed on a button control.

[Visual Basic]
Public Property Image As Image
[C#]
public Image Image {get; set;}
[C++]
public: __property Image* get_Image();
public: __property void set_Image(Image*);
[JScript]
public function get Image() : Image;
public function set Image(Image);

Property Value

The Image displayed on the button control. The default value is a null reference (Nothing in Visual Basic).

Remarks

When the Image property is set, the ImageList property will be set to a null reference (Nothing in Visual Basic), and the ImageIndex property will be set to its default, -1.

Example

The following 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. This code assumes you have a bitmap image named MyBitMap.bmp stored in the C:\Graphics directory, and a reference to the System.Drawing namespace is included.

[Visual Basic] 
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 'SetMyButtonProperties

[C#] 
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;
 }
 

[C++] 
private:
    void SetMyButtonProperties() {
    // Assign an image to the button.
    button1->Image = Image::FromFile(S"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;
    }

[JScript] 
private function 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;
 }
 

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ButtonBase Class | ButtonBase Members | System.Windows.Forms Namespace | ImageList

Show:
© 2014 Microsoft