閱讀英文

共用方式為


HorizontalAlignment 列舉

定義

指定控制項中的物件或文字如何水平對齊於相關的控制項項目。

C#
[System.Runtime.InteropServices.ComVisible(true)]
public enum HorizontalAlignment
C#
public enum HorizontalAlignment
繼承
HorizontalAlignment
屬性

欄位

名稱 Description
Center 2

物件或文字置中對齊控制項項目。

Left 0

物件或文字靠左對齊控制項項目。

Right 1

物件或文字靠右對齊控制項項目。

範例

這個範例示範如何使用 HorizontalAlignment 列舉,將文字對齊控制項專案的左、右或中央。 首先,建立 TextBox 具有特定大小的 ,並將文字字串新增至其中。 然後,使用列舉成員 Center 來對齊 中央的 TextBox 文字。 此範例假設您已建立 Form 具名 Form1TextBox 具名 的 textBox1

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

備註

這個列舉用於許多類別。 這些類別的部分清單為 CheckedListBoxColumnHeaderComboBoxControlPaintLabelListBoxControlRichTextBox 、 和 TextBox

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9