ButtonBase.FlatStyle 屬性

定義

取得或設定按鈕控制項的平面樣式外觀。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

屬性值

FlatStyle

其中一個 FlatStyle 值。One of the FlatStyle values. 預設值是 StandardThe default value is Standard.

例外狀況

所指派的值不是其中一個 FlatStyle 值。The value assigned is not one of the FlatStyle values.

範例

下列程式碼範例會使用衍生類別, Button 並設定其一些通用屬性。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. 此程式碼需要您擁有名為的點陣圖影像 MyBitMap.bmp C:\Graphics ,並儲存在目錄中,而且 System.Drawing 會包含命名空間的參考。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

備註

FlatStyle 和類別的屬性 RadioButton CheckBox 設定為時 System ,控制項會由使用者的作業系統繪製,而檢查對齊是以 CheckAlignTextAlign 屬性值為基礎。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. CheckAlign屬性值不會變更,但控制項的外觀可能會受到影響。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. 例如,如果您的控制項的 CheckBox CheckAlign 屬性值為 ContentAlignmentFor example, if you have a CheckBox control with a CheckAlign property value of ContentAlignment. MiddleCenter、的 TextAlign 屬性值 ContentAlignment.TopRightFlatStyle 屬性值設定為 SystemContentAlignment.TopLeft 當文字對齊保持不變時,核取方塊的對齊方式會顯示為。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.

注意

如果 FlatStyle 屬性設定為,則 FlatStyle.System 不會顯示任何指派給 Image 屬性的影像。If the FlatStyle property is set to FlatStyle.System, any images assigned to the Image property are not displayed.

適用於

另請參閱