I would like to toggle the password visibility of a textbox with a checkbox element. So whenever the state changes I would like to display the password with password characters or plain text.
Using C# I can simply assign a password character for asterisks via
textBox.PasswordChar = '*';
and for plain text
textBox.PasswordChar = '\0';
With VB I currently have this sample code
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
TextBox1.PasswordChar = '\0'
CheckBox1.Text = "Hide password"
Else
TextBox1.PasswordChar = '*'
CheckBox1.Text = "Show password"
End If
End Sub
and found some information here
How do you declare a Char literal in Visual Basic .NET?
I know that '
is considered as a comment so I have to use double-quotes. I can update '*'
to "*"C
but what's the equivalent for '\0'
?
What is the correct way to unmask the textbox password?