ButtonBase.TextAlign Property
.NET Framework 4
Gets or sets the alignment of the text on the button control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System.Drawing.ContentAlignmentOne of the ContentAlignment values. The default is MiddleCenter.
| Exception | Condition |
|---|---|
| InvalidEnumArgumentException |
The value assigned is not one of the ContentAlignment values. |
The following code 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 requires that you have a bitmap image named MyBitMap.bmp stored in the C:\Graphics directory, and that a reference to the System.Drawing namespace is included.
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; }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.