Versión imprimible       Enviar     
Evaluar y enviar comentarios

  Encender vista de ancho de banda bajo
Esta página es específica de
Microsoft Visual Studio 2005/.NET Framework 2.0

Hay además otras versiones disponibles para:
TextBox.PasswordChar (Propiedad)
Obtiene o establece los caracteres utilizados para enmascarar caracteres de una contraseña en un control TextBox de una sola línea.

Espacio de nombres: System.Windows.Forms
Ensamblado: System.Windows.Forms (en system.windows.forms.dll)

Visual Basic (Declaración)
<LocalizableAttribute(True)> _
Public Property PasswordChar As Char
Visual Basic (Uso)
Dim instance As TextBox
Dim value As Char

value = instance.PasswordChar

instance.PasswordChar = value
C#
[LocalizableAttribute(true)] 
public char PasswordChar { get; set; }
C++
[LocalizableAttribute(true)] 
public:
property wchar_t PasswordChar {
    wchar_t get ();
    void set (wchar_t value);
}
J#
/** @property */
public char get_PasswordChar ()

/** @property */
public void set_PasswordChar (char value)
JScript
public function get PasswordChar () : char

public function set PasswordChar (value : char)
XAML
No aplicable.

Valor de propiedad

Carácter utilizado para enmascarar caracteres escritos en un control TextBox de una sola línea. Establezca el valor de esta propiedad en 0 (valor de carácter) si no desea que el control enmascare caracteres a medida que se escriben. Equivale a 0 (valor de carácter) de forma predeterminada.

La propiedad UseSystemPasswordChar tiene prioridad sobre la propiedad PasswordChar. Siempre que UseSystemPasswordChar se establece en true, se utiliza el carácter de contraseña predeterminado del sistema y se omite cualquier carácter establecido por PasswordChar.

Si la propiedad Multiline está establecida en true, el establecimiento de la propiedad PasswordChar no tiene ningún efecto visual. Cuando la propiedad PasswordChar está establecida en true, no se pueden realizar las acciones de cortar, copiar y pegar en el control mediante el uso del teclado, independientemente de si la propiedad Multiline está establecida en true o false.

NotaNota:

En los sistemas operativos en japonés, se aplica la propiedad PasswordChar independientemente de que el valor de la propiedad Multiline sea true o false. En los demás sistemas operativos, la propiedad PasswordChar se aplica únicamente cuando el valor de Multiline es false.

NotaImportante:

Cuando TextBox está en modo de contraseña porque PasswordChar, UseSystemPasswordChar o ReadOnly son true, TextBox está en modo restringido. En este modo, ImeMode está deshabilitado pero el ImeMode actual se almacena en caché de manera que se puede restaurar si el TextBox queda alguna vez con permiso no restringido. Alternar ReadOnly es un escenario común. ImeMode se sombrea mientras el control está en modo restringido. Desde la perspectiva del diseñador, el valor ImeMode mostrado es el valor real.

En el siguiente ejemplo de código se crea un control TextBox que se utiliza para aceptar una contraseña. En este ejemplo se usa la propiedad CharacterCasing para cambiar a mayúsculas todos los caracteres escritos, y la propiedad MaxLength para restringir la longitud de la contraseña a ocho caracteres. En este ejemplo también se utiliza la propiedad TextAlign para centrar la contraseña en el control TextBox.

Visual Basic
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

C#
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;
 }
 
C++
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;
   }
J#
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
JScript
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 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Compatible con: 2.0, 1.0
© 2009 Microsoft Corporation. Reservados todos los derechos. Términos de uso  |  Marcas Registradas  |  Privacidad
Page view tracker