NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Creating a Password Text Box with the TextBox Control

A password box is a Win Forms text box that displays placeholder characters while a user types a string.

To create a password text box

  1. Set the PasswordChar property of the TextBox control to a specific character.

    The PasswordChar property specifies the character displayed in the text box. For example, if you want asterisks displayed in the password box, specify * for the PasswordChar property. Then, regardless of what character a user types in the text box, an asterisk is displayed.

  2. Set the MaxLength property. The property determines how many characters can be typed in the text box. If the maximum length is exceeded, the system emits a beep and the text box does not accept any more characters.

The code below initializes a text box that will accept a string up to 14 characters long and display asterisks in place of the string. The InitializeMyControl procedure will not execute automatically: it must be called.

[Visual Basic]
Private Sub InitializeMyControl()
   With TextBox1
      .Text = ""   ' Set to no text.
      .PasswordChar = "*"   ' asterisk
      .MaxLength = 14   ' After 14, the control beeps.
   End With
End Sub

[C#]

See Also

Controlling the Insertion Point in a TextBox Control | Creating a Read-Only Text Box | Putting Quotation Marks in a String Programmatically | Selecting Text Programmatically in the TextBox Control | Viewing Multiple Lines in the TextBox Control| TextBox Control