C# Windows Form Show and Hide Password Using Checkbox
Hy Readers!!! Today I will show you how you can show and hide password in your Textbox using C#. A checkbox is commonly used for this purpose that either you want to show the password in your textbox or not. Mostly we have to mask the password while login to our application so no one can see this while you are logging on to your account. If you have doubt that you haven’t entered your password correctly then you can use the checkbox that we will use for hiding and show purpose in case of Password.Follow these steps so you can mask or unmask your password on runtime.
Step1: Drag and drop checkbox from toolbox to your form.
Step2: Goto properties of checkbox and set its name and id if you want.
Step3: Now go to checkbox event named CheckedChanged double click on it. It will take you on the cs page where we will add code to mask and unmask the password.
private void showPsw_CheckedChanged(object sender, EventArgs e)
if (cbShowPsw.Checked) //cbShowPsw is the id of the checkbox that we used
tbPsw.PasswordChar = '\0'; //tbPsw is the id of the password's textbox
tbPsw.PasswordChar = '*';
That’s it. Now you can easily mask or unmask your password on RunTime.
Thanks. Happy coding!