How can I mask a password text field and mask it back to a password?

As a password text field set to:

password_txtBox.PasswordChar ="*" 

to be exposed (from the checkbox) and then mask again

without losing a line inside a text field

+9
c # textbox
source share
6 answers

Just set the property to 0 (the default value) to not mask characters.

Source: http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.passwordchar.aspx

+12
source share

For winforms:

 private void checkBoxShowPassword_CheckedChanged(object sender, EventArgs e) { textBoxPassword.PasswordChar = checkBoxShowPassword.Checked ? '\0' : '*'; } 
+19
source share

if you are working with a toggle switch, then

  private void toggleSwitch1_Toggled(object sender, EventArgs e) { if (toggleSwitch1.IsOn==true) { string a= textBox2.Text; textBox2.PasswordChar = '\0'; } if (toggleSwitch1.IsOn==false) { textBox2.PasswordChar = '*'; } } 

here '\ 0' will show a password open for plain text

+3
source share

txtPassword is the Password text box, chkSeePassword is the Show password box. Now add the code to the CheckedChanged event checkbox

 private void chkSeePassword_CheckedChanged(object sender, EventArgs e) { txtPassword.UseSystemPasswordChar = !chkSeePassword.Checked; } 
+1
source share

use this

 private void checkBox1_CheckedChanged(object sender, EventArgs e) { textBox2.PasswordChar = default(char); } 
0
source share

Version VB.Net

 Private Sub checkBoxShowPassword_CheckedChanged(sender As Object, e As System.EventArgs) Handles checkBoxShowPassword.CheckedChanged textBoxPassword.PasswordChar = If(checkBoxShowPassword.Checked, ControlChars.NullChar, "*"C) End Sub 

or

 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged If CheckBox1.Checked Then Me.txt_password.PasswordChar = "*"c Else Me.txt_password.PasswordChar = ControlChars.NullChar End If End Sub 
0
source share

All Articles