Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Ruft ab oder legt fest, wie Text in einem TextBox-Steuerelement ausgerichtet wird.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
<LocalizableAttribute(True)> _
Public Property TextAlign As HorizontalAlignment
'Usage
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)
Eigenschaftenwert
Einer der HorizontalAlignment-Enumerationswerte, der angibt, wie Text im Steuerelement ausgerichtet wird. Der Standardwert ist HorizontalAlignment.Left.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
Der Eigenschaft wurde ein Wert außerhalb des gültigen Wertebereichs der Enumeration zugewiesen. |
Hinweise
Mit dieser Eigenschaft können Sie den Text innerhalb von TextBox entsprechend dem Textlayout des Formulars ausrichten. Wenn sich z. B. alle Steuerelemente an der rechten Seite des Formulars befinden, können Sie die TextAlign-Eigenschaft auf HorizontalAlignment.Right festlegen, sodass der Text am rechten Rand des Steuerelements und nicht entsprechend der Standardeinstellung links ausgerichtet wird.
Hinweis zu Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows CE: Bei Pocket PC-Anwendungen wird für einzeilige Textfelder lediglich die Linksausrichtung unterstützt. Mehrzeilige Textfelder können linksbündig, rechtsbündig oder zentriert ausgerichtet werden.
Beispiel
Im folgenden Codebeispiel wird ein TextBox-Steuerelement erstellt, das zum Akzeptieren eines Kennworts verwendet wird. In diesem Beispiel werden mit der CharacterCasing-Eigenschaft alle Zeichen in Großbuchstaben umgewandelt, und mit der MaxLength-Eigenschaft wird die Kennwortlänge auf acht Zeichen beschränkt. In diesem Beispiel wird des Weiteren die TextAlign-Eigenschaft verwendet, um das Kennwort im TextBox-Steuerelement zu zentrieren.
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;
}
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
TextBox-Klasse
TextBox-Member
System.Windows.Forms-Namespace
HorizontalAlignment-Enumeration