Hide and Show Password Text using Checkbox in C# Windows Application

Let’s create a windows application from scratch to Hide and Show Password Text in C# on a checkbox click.

Here, we will see how to set your Textbox to “show” and “hide” Password in any Registration Form by using Visual C#. This will help you to keep safe your password that you will input in the Textbox when registering in any Registration Form.

Hide and Show Password Text Using Checkbox in C#

Step 1:

Open your visual studio > click on New Project > select visual C# Windows Application > name the project as per your choice > click on OK.

Step 2:

On the Form1 just drag and drop 4 Labels3 Textboxes1 Checkbox, and 1 Button from the toolbox. Change the text of the first label as Registration Form and increase the font size and place it in the center of the Form-like heading. Change the text of other labels as respectively UsernameName, and Password. Change the text of CheckBox1 as Show Password and text of Button1 as Save. our form will look like below image.

Step 3:

Double click on Form1 and add the following code on the form load event.

 private void Form1_Load(object sender, EventArgs e)
        {

            textBox3.UseSystemPasswordChar = true;
        }

Step 4:

Click on the checkbox in form design and go to its property window find the option CheckState and keep it on Unchecked.

Step 5:

Now return back on the form design and double click on Checkbox and write the below code there.

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
          
            if (checkBox1.Checked)
            {
                textBox3.UseSystemPasswordChar = false;
            }
            else
            {
                textBox3.UseSystemPasswordChar = true;
            }

Step 6:

Run the application.

Output:

When we run the application and fill the text in all textboxes we will see that the password field is not visible it is hidden at first.

When we click on the Check Box then the password will show as you can see in the below image.

So in this way, we can easily Show or Hide the Password Text in C# Windows Application with the help of Checkbox.