Let’s create a Visual application from scratch to Hide and Show Password Text in VB.NET on a checkbox click.
Hide and Show Password Text Using Checkbox in VB.NET
Today, we will learn that how to set your Textbox to “show” and “hide” Password in any Registration Form by using Visual Basic. This will help you to keep safe your password that you will input in the Textbox when registering in any Registration Form.
For doing this work we are making a registration form application in which we will use this. so let’s start with the following steps:
Open your visual studio > click on New Project > select visual Basic > name the project as show hide password > click on Next.
On the Form1 just drag and drop 4 Labels, 3 Textboxes, 1 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 respectively Username, Name, and Password. Change the text of CheckBox1 as Show Password and text of Button1 as Save.
Double click on Form1 and add the following code on the form load event.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ‘HIDE THE TEXT OF THE TextBox3 ON THE FIRST LOAD Textbox3.UseSystemPasswordChar = True End Sub End Class
Now return back on the form design and double click on Checkbox and write the below code there.
Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged ‘CHECKING IF THE CHECKBOX WAS CHECKED OR NOT. If CheckBox1.CheckState = CheckState.Checked Then ‘IF TRUE, IT SHOWS THE TEXT textBox3.UseSystemPasswordChar = False Else ‘IF FALSE, IT WILL HIDE THE TEXT AND IT WILL TURN INTO BULLETS. textBox3.UseSystemPasswordChar = True End If End Sub
Run the application.
When we run the application password is not visible it is hidden at first.
When we click on the Check Box then the password will show you can see in the below image.
So in this way, we can easily Show or Hide the Password Text in VB.NET