ButtonBase.FlatStyle 属性

定义

获取或设置按钮控件的平面样式外观。

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

属性值

FlatStyle 值之一。 默认值是 Standard

例外

分配的值不是 FlatStyle 值之一。

示例

下面的代码示例使用派生类, Button 并设置其一些通用属性。 结果将是一个平面按钮,其中文本位于左侧,图像位于右侧。 此代码要求将名为 的 MyBitMap.bmp 位图图像存储在 目录中 C:\Graphics ,并且包含对命名空间的 System.Drawing 引用。

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

注解

FlatStyle当 和 CheckBox 类的 RadioButton 属性设置为 System时,控件由用户的操作系统绘制,检查对齐方式基于 CheckAlignTextAlign 属性值。 属性值 CheckAlign 不会更改,但控件的外观可能会受到影响。 复选框与控件的左边缘或右边缘水平对齐, (左对齐或居中对齐左对齐,右对齐) 保持不变,垂直对齐与描述性文本相同。 例如,如果控件CheckBox的属性值ContentAlignmentCheckAlignMiddleCenterTextAlign,属性值为 ContentAlignment.TopRight,并且 FlatStyle 属性值设置为 System,当文本对齐方式保持不变时,复选框对齐方式将显示ContentAlignment.TopLeft为 。

注意

如果 属性 FlatStyle 设置为 FlatStyle.System,则不会显示分配给 属性 Image 的任何图像。

适用于

另请参阅