HorizontalAlignment 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定控件中的物件或文字相對於控件元素的水準對齊方式。
public enum class HorizontalAlignment
[System.Runtime.InteropServices.ComVisible(true)]
public enum HorizontalAlignment
public enum HorizontalAlignment
[<System.Runtime.InteropServices.ComVisible(true)>]
type HorizontalAlignment =
type HorizontalAlignment =
Public Enum HorizontalAlignment
- 繼承
- 屬性
欄位
| 名稱 | 值 | Description |
|---|---|---|
| Left | 0 | 物件或文字會對齊在控制元件的左側。 |
| Right | 1 | 物件或文字會對齊在控制元件的右側。 |
| Center | 2 | 物件或文字會對齊在控制元件的中心。 |
範例
此範例展示了如何利用 HorizontalAlignment 列舉來將文字對齊到控制元素的左、右或中央。 首先,建立一個特定大小的 , TextBox 並在上面加上文字串。 接著,使用列舉元件 Center 將文字對齊於 TextBox。 這個範例假設你已經建立了一個 Form 名為 Form1 和 TextBoxtextBox1的 。
private:
void Form1_Load( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Add a text String* to the TextBox.
textBox1->Text = "Hello World!";
// Set the size of the TextBox.
textBox1->AutoSize = false;
textBox1->Size = System::Drawing::Size( Width, Height / 3 );
// Align the text in the center of the control element.
textBox1->TextAlign = HorizontalAlignment::Center;
}
private void Form1_Load(object sender, System.EventArgs e)
{
// Add a text string to the TextBox.
textBox1.Text = "Hello World!";
// Set the size of the TextBox.
textBox1.AutoSize = false;
textBox1.Size = new Size(Width, Height/3);
// Align the text in the center of the control element.
textBox1.TextAlign = HorizontalAlignment.Center;
}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Add a text string to the TextBox.
TextBox1.Text = "Hello World!"
' Set the size of the TextBox.
TextBox1.AutoSize = False
TextBox1.Size = New Size(Width, Height/3)
' Align the text in the center of the control element.
TextBox1.TextAlign = HorizontalAlignment.Center
End Sub
備註
這種列舉方式被廣泛應用於多種類別中。 這些類別的部分列表為 CheckedListBox、 ColumnHeader、 ComboBoxControlPaintLabelListBoxControlRichTextBoxTextBox和 。