Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

TextBox::PasswordChar Property

Gets or sets the character used to mask characters of a password in a single-line TextBox control.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
property wchar_t PasswordChar {
	wchar_t get ();
	void set (wchar_t value);
}

Property Value

Type: System::Char
The character used to mask characters entered in a single-line TextBox control. Set the value of this property to 0 (character value) if you do not want the control to mask characters as they are typed. Equals 0 (character value) by default.

The UseSystemPasswordChar property has precedence over the PasswordChar property. Whenever the UseSystemPasswordChar is set to true, the default system password character is used and any character set by PasswordChar is ignored.

When the PasswordChar property is set, cut and copy actions in the control using the keyboard cannot be performed.

Important noteImportant

When the TextBox is in password mode because PasswordChar, UseSystemPasswordChar, or ReadOnly is true, the TextBox is in restricted mode. In this mode, the ImeMode is disabled, but the current ImeMode is cached so that it can be restored if the TextBox ever becomes unrestricted. Toggling the ReadOnly is a common scenario. The ImeMode is shadowed while the control is in restricted mode. From the designer perspective, the ImeMode value shown is the actual value.

The following code example creates a TextBox control that is used to accept a password. This example uses the CharacterCasing property to change all characters typed to lowercase and the MaxLength property to restrict the password length to eight characters. This example also uses the TextAlign property to center the password in the TextBox control.

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;
   }

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft