Showing and Hiding Password in Windows Forms Application

Changing PasswordChar Property by Code

In Windows applications, using the PasswordChar property of the text box, the characters entered in the box can be made to appear * or in different formats. In this way, it is ensured that the password entered by the user is not visible to other eyes.

So, can we offer the user the chance to show the characters they type in order to control them? 

The example below uses a text box and a button. The PasswordChar property of the text box is initially set to "*" (from the Properties panel). It also says "Show" on the button.

Each time the button is clicked, the PasswordChar property of the text box is checked, if the PasswordChar property is "*", it is removed and "Hide" is written on the button, otherwise the PasswordChar property is made "*" again and "Show" is written on the button.

private void button3_Click(object sender, EventArgs e)
{
    if(textBox9.PasswordChar.ToString()=="*")
    {
        textBox9.PasswordChar = char.Parse("\0");
        button3.Text = "Hide";
    }
    else
    {
        textBox9.PasswordChar = char.Parse("*");
        button3.Text = "Show";
    }
            
}

 

c# windows forms show and hide password in textbox by button, show and hide password with button, change passwordchar, change passwordchar

EXERCISES

There are no examples related to this subject.



COMMENTS




Read 899 times.

Online Users: 354



showing-or-hiding-password-in-windows-forms-application