英語で読む

次の方法で共有


HorizontalAlignment 列挙型

定義

コントロールのオブジェクトまたはテキストをコントロールの要素に合わせて水平方向に配置する場合、どのように配置するのかを指定します。

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

フィールド

名前 説明
Center 2

オブジェクトまたはテキストは、コントロール要素の中央に配置されます。

Left 0

オブジェクトまたはテキストは、コントロール要素の左側に配置されます。

Right 1

オブジェクトまたはテキストは、コントロール要素の右側に配置されます。

この例では、 列挙を HorizontalAlignment 使用して、コントロール要素の左、右、または中央にテキストを配置する方法を示します。 まず、特定のサイズの を TextBox 作成し、それにテキスト文字列を追加します。 次に、 列挙メンバー Center を使用して、 の中央にテキストを配置します TextBox。 この例では、名前付き と という名前Form1textBox1の がTextBoxForm作成されていることを前提としています。

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

注釈

この列挙は、多数のクラスで使用されます。 これらのクラスの一部の一覧は、CheckedListBoxColumnHeader、、ComboBoxControlPaintListBoxLabelControlRichTextBoxおよび 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