views:

371

answers:

3

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!

A: 

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

if ( e.KeyChar == 13) {
    /* This is the enter key. Do stuff. */
}
Nazadus
i could do that, that is.. if the maskedtextbox would allow hard returns..
KevinDeus
+5  A: 

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

Colin Mackay
You may also be interested to note that you can submit on Enter by using a Button with AcceptButton property on the form set to that button: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton(VS.80).aspx
Colin Mackay
yes this is very helpful. Thanks!
KevinDeus
+1  A: 

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.

Marineio