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)

[LocalizableAttribute(true)] 
public FlatStyle FlatStyle { get; set; }
/** @property */
public FlatStyle get_FlatStyle ()

/** @property */
public void set_FlatStyle (FlatStyle value)

public function get FlatStyle () : FlatStyle

public function set FlatStyle (value : FlatStyle)

Not applicable.

Property Value

One of the FlatStyle values. The default value is Standard.

Exception typeCondition

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

private void SetMyButtonProperties()
{
    // Assign an image to the button.
    button1.set_Image(Image.FromFile("C:\\Graphics\\MyBitmap.bmp"));

    // Align the image and text on the button.
    button1.set_ImageAlign(ContentAlignment.MiddleRight);
    button1.set_TextAlign(ContentAlignment.MiddleLeft);

    // Give the button a flat appearance.
    button1.set_FlatStyle(FlatStyle.Flat);
} //SetMyButtonProperties

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft