在我们做winform登录页面时,为了保护用户因素要把密码显示为"*"号,点击按键可以看到密码
要实现这个功能要用到textBox中的PasswordChar方法,登录界面如下:
实现代码如下:
namespace SQLProjectDemo { public partial class LoginForm : UIForm {string password; public LoginForm() { InitializeComponent(); } private void password_textBox_TextChanged(object sender, System.EventArgs e) { password_textBox.PasswordChar = '*'; password = password_textBox.Text; } private void showpassword_btn_MouseDown(object sender, MouseEventArgs e) { password_textBox.PasswordChar = new char(); } private void showpassword_btn_MouseUp(object sender, MouseEventArgs e) { password_textBox.PasswordChar = '*'; } } }
标签:暗文,PasswordChar,void,object,private,明文,切换,password,textBox From: https://www.cnblogs.com/ywwwik/p/17930320.html