如何在 vb.net 中获得“显示密码”效果?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33950688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:35:57  来源:igfitidea点击:

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

vb.netpasswords

提问by Brayden

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.

我正在使用各种选项在visual basic 2015中制作电子邮件登录程序,其中一个选项是显示密码或不显示密码的选项,可能带有复选框。它只是一个简单的标准 Windows 窗体应用程序,我对它比较陌生。

Edit: Answered by jmcilhinney. Thanks! :D

编辑:由 jmcilhinney 回答。谢谢!: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

回答by jmcilhinney

Set the UseSystemPasswordCharproperty of your TextBoxto Trueto mask the password.

设置UseSystemPasswordChar你的财产TextBox,以True掩盖密码。

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

回答by Hector Favio Mosquera

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

回答by CubaCompiler

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

你必须做一些改变。将您的密码文本框更改UseSystemPasswordChar为 false 并更改PasswordCharChar(0)。像这样的东西:

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