TextBox.PasswordChar 获取焦点显示可见密码,失去焦点密码不可见。

因为PasswordChar是一个char,所以清除设置时,使用Convert.ToChar(0);就行,那么Convert.ToChar(0)得到的值是什么呢,ASCII码值,你懂的……

        public Form1()
        {
            InitializeComponent();

            this.txtPassword.Text = "your password";
            this.txtPassword.LostFocus += new EventHandler(txtPassword_LostFocus);
            this.txtPassword.Enter += new EventHandler(txtPassword_Enter);
            
        }

        void txtPassword_Enter(object sender, EventArgs e)
        {
            //获取焦点时则移除PasswordChar的设置,即可显示正常的字符了
            this.txtPassword.PasswordChar =Convert.ToChar(0);
        }

        void txtPassword_LostFocus(object sender, EventArgs e)
        {
            //焦点失去时,文本框中则显示*号
            this.txtPassword.PasswordChar = '*';
        }

  

相关文章:

  • 2022-12-23
  • 2022-01-15
  • 2021-12-19
  • 2017-12-12
  • 2021-12-19
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2022-02-02
  • 2021-12-19
  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
相关资源
相似解决方案