ButtonBase.FlatStyle 属性

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

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
<LocalizableAttribute(True)> _
Public Property FlatStyle As FlatStyle
用法
Dim instance As ButtonBase
Dim value As FlatStyle

value = instance.FlatStyle

instance.FlatStyle = value
[LocalizableAttribute(true)] 
public FlatStyle FlatStyle { get; set; }
[LocalizableAttribute(true)] 
public:
property FlatStyle FlatStyle {
    FlatStyle get ();
    void set (FlatStyle value);
}
/** @property */
public FlatStyle get_FlatStyle ()

/** @property */
public void set_FlatStyle (FlatStyle value)
public function get FlatStyle () : FlatStyle

public function set FlatStyle (value : FlatStyle)

属性值

FlatStyle 值之一。默认值为 Standard

异常

异常类型 条件

InvalidEnumArgumentException

分配的值不是 FlatStyle 值之一。

备注

RadioButtonCheckBox 类的 FlatStyle 属性设置为 System 时,控件由用户的操作系统绘制,并且复选框的对齐方式基于 CheckAlignTextAlign 属性值。未更改 CheckAlign 属性值,但可能会影响控件的外观。复选框会与控件的左边缘或右边缘水平对齐(左对齐或居中对齐显示为左对齐,右对齐保持不变),并且像描述性文本一样进行垂直对齐。例如,如果有一个 CheckBox 控件,其 CheckAlign 属性的值为 ContentAlignment.MiddleCenterTextAlign 属性值为 ContentAlignment.TopRight,并且 FlatStyle 属性值被设置为 System,则该复选框的对齐方式将显示为 ContentAlignment.TopLeft,而文本对齐方式保持不变。

提示

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

示例

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

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 'SetMyButtonProperties
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 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 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ButtonBase 类
ButtonBase 成员
System.Windows.Forms 命名空间
System.Drawing.ContentAlignment