This documentation is archived and is not being maintained.

ButtonBase.TextAlign Property

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

[Visual Basic]
Public Overridable Property TextAlign As ContentAlignment
[C#]
public virtual ContentAlignment TextAlign {get; set;}
[C++]
public: __property virtual ContentAlignment get_TextAlign();
public: __property virtual void set_TextAlign(ContentAlignment);
[JScript]
public function get TextAlign() : ContentAlignment;
public function set TextAlign(ContentAlignment);

Property Value

One of the ContentAlignment values. The default 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 | ImageAlign

Show: