共用方式為


ButtonBase.TextAlign 屬性

定義

取得或設定按鈕控制項上文字的對齊方式。

public:
 virtual property System::Drawing::ContentAlignment TextAlign { System::Drawing::ContentAlignment get(); void set(System::Drawing::ContentAlignment value); };
public virtual System.Drawing.ContentAlignment TextAlign { get; set; }
member this.TextAlign : System.Drawing.ContentAlignment with get, set
Public Overridable Property TextAlign As ContentAlignment

屬性值

ContentAlignment

其中一個 ContentAlignment 值。 預設為 MiddleCenter

例外狀況

所指派的值不是其中一個 ContentAlignment 值。

範例

下列程式碼範例會使用衍生類別, 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

適用於

另請參閱