简体   繁体   中英

How do I get a "show password" effect in vb.net?

I am making an email login program in visual basic 2015 with various options, one of them being the option to show password or not with probably a check box. It is just a simple, standard windows forms application, I am relatively new to it.

Edit: Answered by jmcilhinney. Thanks! :D

Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

'Display plain text if and only if check box is checked.

TextBox1.UseSystemPasswordChar = Not CheckBox1.Checked

End Sub

Set the UseSystemPasswordChar property of your TextBox to True to mask the password.

Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
    'Display plain text if and only if check box is checked.
    TextBox1.UseSystemPasswordChar = Not CheckBox1.Checked
End Sub
Private Sub txtPassword_MouseHover(sender As Object, e As EventArgs) Handles txtPassword.MouseHover
    txtPassword.PasswordChar = ""
End Sub

Private Sub txtPassword_MouseLeave(sender As Object, e As EventArgs) Handles txtPassword.MouseLeave
    txtPassword.PasswordChar = "*"
End Sub

You have to do couple of changes. Change your password textbox UseSystemPasswordChar to false and the PasswordChar to Char(0) . Something like this:

If chkViewPassword.Checked Then txbPwd.PasswordChar = Convert.ToChar(0) Else txbPwd.PasswordChar = Convert.ToChar("*")
    txbSMTPPwd.UseSystemPasswordChar = Not chkViewPassword.Checked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM