To reset the password character to not mask, set it to the null character:
txtPassword.PasswordChar = '\0';
Default value specified on MSDN
문제
I have a textbox that I'm using as a password box, and I want to have the default password visible, and then when it is changed, hide it with '*'
. So when the user opens the form, the Password text box will already have "welcome1" in the text box, but when they change it, the password will appear as "*".
What I have at the moment:
if (txtPassword.Text == "welcome1")
{
// Set txtPassword.PasswordChar to null or empty.
}
else { txtPassword.PasswordChar = '*'; }
해결책
To reset the password character to not mask, set it to the null character:
txtPassword.PasswordChar = '\0';
Default value specified on MSDN
다른 팁
Nevermind, just figured it out:
private void txtPassword_TextChanged(object sender, EventArgs e)
{
if (txtPassword.Text != "welcome1")
{
txtPassword.PasswordChar = '*';
}
}
Maybe use 2 text boxes. 1e Visible true 2e Visible false And set the 2e text box Password Char to * With a mouse click event on the first text box. When somebody clicks the text box to type a password the text box changes.
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
textBox1.Text = "";
textBox1.Visible = false;
textBox2.Visible = true;
textBox2.Focus();
}
Also put a form mouse click for if thy didn't type a text , go back to text box 1 or something like that.
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (textBox2.Text == "")
{
textBox2.Visible = false;
textBox1.Visible = true;
textBox1.Text = "Welcome1";
}
}