How can I unmask password text box and mask it bac

2019-01-07 23:17发布

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

标签: c# textbox
7条回答
姐就是有狂的资本
2楼-- · 2019-01-07 23:57

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.

查看更多
你好瞎i
3楼-- · 2019-01-08 00:07

txtPassword is the Password textbox, chkSeePassword is the Show password checkbox. Now add some code to the checkbox's CheckedChanged event

private void chkSeePassword_CheckedChanged(object sender, EventArgs e)
{
        txtPassword.UseSystemPasswordChar = !chkSeePassword.Checked;
}
查看更多
Root(大扎)
4楼-- · 2019-01-08 00:08

One of the easiest method to show and hide password is by using radio button inside password text box

The properties of radio button should be like:

this.radioBtn_ShowHidePassword.AutoCheck = false;    

then the clicking activity has to be taken care manually just making it to be reverse of present state in its "Click" event

private void radioBtn_ShowHidePassword_Click(object sender, EventArgs e)
{
 radioBtn_ShowHidePassword.Checked = (! radioBtn_ShowHidePassword.Checked);
}

then finally the easiest way of show and hide password

private void radioBtn_ShowHidePassword_CheckedChanged(object sender, EventArgs e)
{
   txtBoxPassword.PasswordChar = radioBtn_ShowHidePassword.Checked ? '\0' : '*';
   // here we can even include the code for changing the default picture of button to two different
   //representation like closed eye and opened eye which resembles Windows login
}
查看更多
Viruses.
5楼-- · 2019-01-08 00:12

For winforms:

private void checkBoxShowPassword_CheckedChanged(object sender, EventArgs e) {
   textBoxPassword.PasswordChar = checkBoxShowPassword.Checked ? '\0' : '*';
}
查看更多
别忘想泡老子
6楼-- · 2019-01-08 00:19

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

查看更多
7楼-- · 2019-01-08 00:24

use this one

private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        textBox2.PasswordChar = default(char);
    }
查看更多
登录 后发表回答