次の方法で共有


ButtonBase.FlatStyle プロパティ

ボタン コントロールのフラット スタイルの外観を取得または設定します。

Public Property FlatStyle As FlatStyle
[C#]
public FlatStyle FlatStyle {get; set;}
[C++]
public: __property FlatStyle get_FlatStyle();public: __property void set_FlatStyle(FlatStyle);
[JScript]
public function get FlatStyle() : FlatStyle;public function set FlatStyle(FlatStyle);

プロパティ値

FlatStyle 値の 1 つ。既定値は Standard です。

例外

例外の種類 条件
InvalidEnumArgumentException 代入された値が、 FlatStyle 値ではありません。

解説

RadioButton クラスおよび CheckBox クラスの FlatStyle プロパティが FlatStyle.System に設定されている場合、コントロールはユーザーのオペレーティング システムによって描画され、チェックの配置は CheckAlign プロパティ値と TextAlign プロパティ値に基づいて決定されます。 CheckAlign プロパティ値は変わりませんが、コントロールの外観に影響を与えることがあります。チェック ボックスは、水平方向にはコントロールの左端または右端に寄せられ、左寄せまたは中央寄せの場合は左寄せになり、右寄せの場合は変わりません。垂直方向には、説明するテキストと同じように配置されます。たとえば、 CheckAlign プロパティ値が ContentAlignment.MiddleCenter で、 TextAlign プロパティ値が ContentAlignment.TopRightCheckBox コントロールがあり、 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

[C#] 
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;
 }
 

[C++] 
private:
    void SetMyButtonProperties() {
    // Assign an image to the button.
    button1->Image = Image::FromFile(S"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;
    }

[JScript] 
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 NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

ButtonBase クラス | ButtonBase メンバ | System.Windows.Forms 名前空間