3

I am having a textbox for password field, I want to add a Checkbox that toggles the password into plain text.

I did the following coding for it.

txtpwd.PasswordChar = (char)(byte)32;

but this simply hides not showing the plain text of what is typed in textbox field.

any body can help?

gehho
  • 9,049
  • 3
  • 45
  • 59
Bibi Tahira
  • 1,082
  • 5
  • 15
  • 39

1 Answers1

10

Here is the solution, I added CheckBox with name chkpwd and on its CheckedChange event i added this code

private void chkpwd_CheckedChanged(object sender, EventArgs e)
    {
        if (chkpwd.Checked)
            txtpwd.PasswordChar = '\0';
        else
            txtpwd.PasswordChar = '*';
    }

This will show plain text when checkbox's checked property true

DareDevil
  • 5,249
  • 6
  • 50
  • 88