Export (0) Print
Expand All

ButtonBase.FlatStyle Property

Gets or sets the flat style appearance of the button control.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public FlatStyle FlatStyle { get; set; }

Property Value

Type: System.Windows.Forms.FlatStyle
One of the FlatStyle values. The default value is Standard.

ExceptionCondition
InvalidEnumArgumentException

The value assigned is not one of the FlatStyle values.

When the FlatStyle property of the RadioButton and CheckBox classes is set to System, the control is drawn by the user's operating system and the check alignment is based upon the CheckAlign and TextAlign property values. The CheckAlign property value is not changed, but the appearance of the control can be affected. The check box is horizontally aligned with either the left or right edge of the control (a left or center alignment appears left aligned, right remains unchanged), and vertically aligned the same as the descriptive text. For example, if you have a CheckBox control with a CheckAlign property value of ContentAlignment. MiddleCenter, a TextAlign property value of ContentAlignment.TopRight, and the FlatStyle property value is set to System, the check box alignment will appear to be ContentAlignment.TopLeft while the text alignment remains unchanged.

NoteNote

If the FlatStyle property is set to FlatStyle.System, any images assigned to the Image property are not displayed.

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;
 }
 

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft