Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I unmask password text box and mask it back to password?

Tags:

c#

textbox

How can password textbox that set to :

password_txtBox.PasswordChar ="*"

to be unmasked ( from checkbox ) and then mask again
without loosing the string inside the textbox

like image 556
user63898 Avatar asked Nov 18 '11 16:11

user63898


3 Answers

For winforms:

private void checkBoxShowPassword_CheckedChanged(object sender, EventArgs e) {
   textBoxPassword.PasswordChar = checkBoxShowPassword.Checked ? '\0' : '*';
}
like image 77
Otiel Avatar answered Oct 07 '22 04:10

Otiel


Just set the property to '\0' (which is the default value) to not mask characters.

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

Note: notice that '\0' is different from '0'. The first one is the null character, white '0' is the character that will be displayed as 0.

like image 43
Renaud Dumont Avatar answered Oct 07 '22 02:10

Renaud Dumont


If you are working with toggle switch then

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

here '\0' will show to password filed to plain text

like image 7
Adiii Avatar answered Oct 07 '22 04:10

Adiii