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
For winforms:
private void checkBoxShowPassword_CheckedChanged(object sender, EventArgs e) {
textBoxPassword.PasswordChar = checkBoxShowPassword.Checked ? '\0' : '*';
}
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With