TextBox.TextAlign Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém ou define como o texto está alinhado num TextBox controlo.
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
Valor de Propriedade
Um dos HorizontalAlignment valores de enumeração que especifica como o texto está alinhado no controlo. A predefinição é HorizontalAlignment.Left.
Exceções
Um valor que não está dentro do intervalo de valores válidos para a enumeração foi atribuído à propriedade.
Exemplos
O seguinte exemplo de código cria um TextBox controlo que é usado para aceitar uma palavra-passe. Este exemplo usa a CharacterCasing propriedade para alterar todos os caracteres digitados para minúsculas e a MaxLength propriedade para restringir o comprimento da palavra-passe a oito caracteres. Este exemplo também usa a TextAlign propriedade para centralizar a palavra-passe no TextBox controlo.
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
Observações
Pode usar esta propriedade para alinhar o texto dentro de um TextBox para corresponder à disposição do texto no seu formulário. Por exemplo, se os seus controlos estiverem todos localizados no lado direito do formulário, pode definir a TextAlign propriedade para HorizontalAlignment.Right, e o texto ficará alinhado com o lado direito do controlo em vez do alinhamento padrão à esquerda.