This question already has an answer here:
- How can I unmask password text box and mask it back to password? 7 answers
I have a textbox
in a c# windows form i am having problems in assigning a null values to a PasswordChar
. What i want to do is that if a checkbox
is checked then the PasswordChar
should be null
i.e the actual text should be displayed else the PasswordChar
should be *
. This what i have tried
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (!checkBox1.Checked)
{
txtPassword.PasswordChar = '*';
}
else
{
txtPassword.PasswordChar = '';
}
}
but this line
txtPassword.PasswordChar = '';
is generating an error. I have even tried
txtPassword.PasswordChar = null;
but i still get an error.
Please help me correct my code.