次の方法で共有


ButtonBase.TextAlign プロパティ

ボタン コントロールのテキストの配置を取得または設定します。

Public Overridable Property TextAlign As ContentAlignment
[C#]
public virtual ContentAlignment TextAlign {get; set;}
[C++]
public: __property virtual ContentAlignment get_TextAlign();public: __property virtual void set_TextAlign(ContentAlignment);
[JScript]
public function get TextAlign() : ContentAlignment;public function set TextAlign(ContentAlignment);

プロパティ値

ContentAlignment 値の 1 つ。既定値は MiddleCenter です。

例外

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

使用例

派生クラス 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 名前空間 | ImageAlign