TextBox.PasswordChar Propriedade

Definição

Obtém ou define o carácter usado para mascarar caracteres de uma palavra-passe num controlo de linha TextBox única.

public:
 property char PasswordChar { char get(); void set(char value); };
public char PasswordChar { get; set; }
member this.PasswordChar : char with get, set
Public Property PasswordChar As Char

Valor de Propriedade

O carácter usado para mascarar caracteres era introduzido num controlo de linha TextBox única. Defina o valor desta propriedade para '0' (U+0000) se não quiser que o controlo mascare caracteres enquanto são digitados. O valor padrão é '0' (U+0000).

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

A UseSystemPasswordChar propriedade tem precedência sobre a PasswordChar propriedade. Sempre que o UseSystemPasswordChar é definido para true, é usado o carácter padrão da palavra-passe do sistema e qualquer carácter definido por PasswordChar é ignorado.

Quando a PasswordChar propriedade está definida, não podem ser realizadas ações de corte e cópia no controlo usando o teclado.

Importante

Quando o TextBox está em modo de palavra-passe porque PasswordChar, UseSystemPasswordChar, ou ReadOnly é true, o TextBox está em modo restrito. Neste modo, o ImeMode está desativado, mas a corrente ImeMode é armazenada em cache para que possa ser restaurada caso alguma TextBox vez se torne irrestrito. Alternar o ReadOnly é um cenário comum. É ImeMode sombreado enquanto o controlo está em modo restrito. Do ponto de vista do designer, o ImeMode valor mostrado é o valor real.

Aplica-se a