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

備註

當 和 CheckBox 類別的 RadioButton 屬性設定 System 為 時,控制項是由使用者的作業系統繪製,而且檢查對齊方式是以 和 TextAlign 屬性值為基礎 CheckAlignFlatStyle CheckAlign屬性值不會變更,但控制項的外觀可能會受到影響。 核取方塊會水準對齊控制項的左邊緣或右邊緣, (靠左對齊或置中對齊,靠右維持不變) ,垂直對齊與描述性文字相同。 例如,如果您有 CheckBox 屬性值為 CheckAlignContentAlignment 控制項。 MiddleCenterTextAlign、的 ContentAlignment.TopRight 屬性值,且 FlatStyle 屬性值設定 System 為 ,核取方塊對齊方式會顯示為 ContentAlignment.TopLeft ,而文字對齊方式保持不變。

注意

FlatStyle如果 屬性設定 FlatStyle.System 為 ,則不會顯示指派給 Image 屬性的任何影像。

適用於

另請參閱