แก้ไข

แชร์ผ่าน


ButtonBase.FlatStyle Property

Definition

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

public:
 property System::Windows::Forms::FlatStyle FlatStyle { System::Windows::Forms::FlatStyle get(); void set(System::Windows::Forms::FlatStyle value); };
public System.Windows.Forms.FlatStyle FlatStyle { get; set; }
member this.FlatStyle : System.Windows.Forms.FlatStyle with get, set
Public Property FlatStyle As FlatStyle

Property Value

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

Exceptions

The value assigned is not one of the FlatStyle values.

Examples

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

Remarks

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.

Note

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

Applies to

See also