KevinDeus
KevinDeus

Reputation: 12178

Password Character not working on System.Windows.Forms.TextBox

Thats it really..

I am using VS2008 Express.

All the samples say just to set the PasswordChar, but nothing gets masked.

I also tried setting the "UseSystemPasswordChar" = true.. no luck..

   // Set to no text.
   textBox1.Text = "";
   // The password character is an asterisk.
   textBox1.PasswordChar = '*';
   // The control will allow no more than 14 characters.
   textBox1.MaxLength = 14;

The reason I'm using a TextBox is because I want the user to be able to hit return and it submits the data. Its important to note I guess that I have MultiLine = true so that I can capture the return.

I can't seem to be able to capture a return with a maskedTextBox. All I get is a system beep.

a solution to either is fine for me!

Upvotes: 1

Views: 9045

Answers (3)

Marineio
Marineio

Reputation: 415

UseSystemPasswordChar doesn't function when Multiline is set to true. The standard Windows Forms textbox accepts returns even when Multiline = false.

Solution: Set Multiline = False, and set a button on your form to use the AcceptButton property, or capture the return/enter key in the "KeyPress" event of the textbox.

Upvotes: 3

Colin Mackay
Colin Mackay

Reputation: 19175

If you read the documentation is says "If the Multiline property is set to true, setting the PasswordChar property has no visual effect."

Upvotes: 10

Kenny Mann
Kenny Mann

Reputation: 900

When using a maskedTextBox capture the key press and do something like:

if ( e.KeyChar == 13) {
    /* This is the enter key. Do stuff. */
}

Upvotes: -1

Related Questions