TextBox.TextAlign Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает или задает выравнивание текста в элементе TextBox управления.
public:
property System::Windows::Forms::HorizontalAlignment TextAlign { System::Windows::Forms::HorizontalAlignment get(); void set(System::Windows::Forms::HorizontalAlignment value); };
public System.Windows.Forms.HorizontalAlignment TextAlign { get; set; }
member this.TextAlign : System.Windows.Forms.HorizontalAlignment with get, set
Public Property TextAlign As HorizontalAlignment
Значение свойства
Одно из HorizontalAlignment значений перечисления, указывающее, как текст выравнивается в элементе управления. Значение по умолчанию — HorizontalAlignment.Left.
Исключения
Значение, которое не находится в диапазоне допустимых значений перечисления, было назначено свойству.
Примеры
В следующем примере кода создается элемент управления, используемый TextBox для принятия пароля. В этом примере свойство используется CharacterCasing для изменения всех символов, введенных в строчный регистр, и MaxLength свойство, ограничивающее длину пароля до восьми символов. В этом примере также используется TextAlign свойство для центра пароля в элементе TextBox управления.
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.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 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
Комментарии
Это свойство можно использовать для выравнивания текста в пределах a TextBox , чтобы соответствовать макету текста в форме. Например, если элементы управления находятся в правой части формы, можно задать TextAlign для свойства HorizontalAlignment.Rightзначение, а текст будет выровнен с правой стороны элемента управления вместо выравнивания по умолчанию слева.