This documentation is archived and is not being maintained.

ButtonBase.ImageAlign Property

Gets or sets the alignment of the image on the button control.

[Visual Basic]
Public Property ImageAlign As ContentAlignment
[C#]
public ContentAlignment ImageAlign {get; set;}
[C++]
public: __property ContentAlignment get_ImageAlign();
public: __property void set_ImageAlign(ContentAlignment);
[JScript]
public function get ImageAlign() : ContentAlignment;
public function set ImageAlign(ContentAlignment);

Property Value

One of the ContentAlignment values. The default value is MiddleCenter.

Exceptions

Exception Type Condition
InvalidEnumArgumentException The value assigned is not one of the ContentAlignment values.

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 | TextAlign

Show: