TextBox.TextAlign プロパティ

TextBox コントロールでテキストをどのように配置するかを取得または設定します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

構文

'宣言
<LocalizableAttribute(True)> _
Public Property TextAlign As HorizontalAlignment
'使用
Dim instance As TextBox
Dim value As HorizontalAlignment

value = instance.TextAlign

instance.TextAlign = value
[LocalizableAttribute(true)] 
public HorizontalAlignment TextAlign { get; set; }
[LocalizableAttribute(true)] 
public:
property HorizontalAlignment TextAlign {
    HorizontalAlignment get ();
    void set (HorizontalAlignment value);
}
/** @property */
public HorizontalAlignment get_TextAlign ()

/** @property */
public void set_TextAlign (HorizontalAlignment value)
public function get TextAlign () : HorizontalAlignment

public function set TextAlign (value : HorizontalAlignment)

プロパティ値

コントロールでテキストをどのように配置するかを指定する HorizontalAlignment 列挙値の 1 つ。既定値は HorizontalAlignment.Left です。

例外

例外の種類 条件

InvalidEnumArgumentException

列挙体の有効値の範囲内にない値が、プロパティに代入されました。

解説

このプロパティを使用して、フォーム上のテキストのレイアウトに合うように TextBox 内のテキストを配置できます。たとえば、コントロールがすべてフォームの右側に配置されている場合は、TextAlign プロパティを HorizontalAlignment.Right に設定すると、テキストは既定の左揃えではなく、コントロールの右側に配置されます。

Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows CE プラットフォームメモ : Pocket PC ベースのアプリケーションの場合、単一行テキスト ボックスでは左揃えだけがサポートされます。複数行テキスト ボックスでは、左揃え、右揃え、または中央揃えで配置できます。

使用例

パスワードを受け取るために使用される TextBox コントロールを作成するコード例を次に示します。この例では、CharacterCasing プロパティを使用して、入力されたすべての文字を大文字に変更します。また、MaxLength プロパティを使用して、パスワード長を 8 文字に制限します。この例では、TextAlign プロパティも使用して、TextBox コントロールの中央にパスワードを配置します。

Public Sub CreateMyPasswordTextBox()
    ' Create an instance of the TextBox control.
    Dim textBox1 As New TextBox()
    ' Set the maximum length of text in the control to eight.
    textBox1.MaxLength = 8
    ' Assign the asterisk to be the password character.
    textBox1.PasswordChar = "*"c
    ' Change all text entered to be lowercase.
    textBox1.CharacterCasing = CharacterCasing.Lower
    ' Align the text in the center of the TextBox control.
    textBox1.TextAlign = HorizontalAlignment.Center
End Sub
public void CreateMyPasswordTextBox()
 {
    // Create an instance of the TextBox control.
    TextBox textBox1 = new TextBox();
    // Set the maximum length of text in the control to eight.
    textBox1.MaxLength = 8;
    // Assign the asterisk to be the password character.
    textBox1.PasswordChar = '*';
    // Change all text entered to be lowercase.
    textBox1.CharacterCasing = CharacterCasing.Lower;
    // Align the text in the center of the TextBox control.
    textBox1.TextAlign = HorizontalAlignment.Center;
 }
 
public:
   void CreateMyPasswordTextBox()
   {
      // Create an instance of the TextBox control.
      TextBox^ textBox1 = gcnew TextBox;
      // Set the maximum length of text in the control to eight.
      textBox1->MaxLength = 8;
      // Assign the asterisk to be the password character.
      textBox1->PasswordChar = '*';
      // Change all text entered to be lowercase.
      textBox1->CharacterCasing = CharacterCasing::Lower;
      // Align the text in the center of the TextBox control.
      textBox1->TextAlign = HorizontalAlignment::Center;
   }
public void CreateMyPasswordTextBox()
{
    // Create an instance of the TextBox control.
    TextBox textBox1 = new TextBox();
    // Set the maximum length of text in the control to eight.
    textBox1.set_MaxLength(8);
    // Assign the asterisk to be the password character.
    textBox1.set_PasswordChar('*');
    // Change all text entered to be lowercase.
    textBox1.set_CharacterCasing(CharacterCasing.Lower);
    // Align the text in the center of the TextBox control.
    textBox1.set_TextAlign(HorizontalAlignment.Center);
} //CreateMyPasswordTextBox
public function CreateMyPasswordTextBox()
 {
    // Create an instance of the TextBox control.
    textBox1 = new TextBox();
    // Set the maximum length of text in the control to eight.
    textBox1.MaxLength = 8;
    // Assign the asterisk to be the password character.
    textBox1.PasswordChar = '*';
    // Change all text entered to be lowercase.
    textBox1.CharacterCasing = CharacterCasing.Lower;
    // Align the text in the center of the TextBox control.
    textBox1.TextAlign = HorizontalAlignment.Center;
 }
 

プラットフォーム

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0、1.0

参照

関連項目

TextBox クラス
TextBox メンバ
System.Windows.Forms 名前空間
HorizontalAlignment 列挙体