How can I unmask password text box and mask it back to password?

前端 未结 7 1068
情深已故
情深已故 2020-11-27 21:36

How can password textbox that set to :

password_txtBox.PasswordChar =\"*\"

to be unmasked ( from checkbox ) and then mask again
without

7条回答
  •  囚心锁ツ
    2020-11-27 21:58

    One of the easiest method to show and hide password is by using radio button inside password text box

    The properties of radio button should be like:

    this.radioBtn_ShowHidePassword.AutoCheck = false;    
    

    then the clicking activity has to be taken care manually just making it to be reverse of present state in its "Click" event

    private void radioBtn_ShowHidePassword_Click(object sender, EventArgs e)
    {
     radioBtn_ShowHidePassword.Checked = (! radioBtn_ShowHidePassword.Checked);
    }
    

    then finally the easiest way of show and hide password

    private void radioBtn_ShowHidePassword_CheckedChanged(object sender, EventArgs e)
    {
       txtBoxPassword.PasswordChar = radioBtn_ShowHidePassword.Checked ? '\0' : '*';
       // here we can even include the code for changing the default picture of button to two different
       //representation like closed eye and opened eye which resembles Windows login
    }
    

提交回复
热议问题