【发布时间】:2015-11-19 20:39:04
【问题描述】:
好吧,我想要一个密码文本框和一个确认密码文本框,但我不确定如何正确设置它们。
我有以下几点:
// This is where the user will enter the password for the product owner they wish to add.
private void textBoxPassword_TextChanged(object sender, EventArgs e)
{
// Each character of the password will display as an asterisk.
textBoxPassword.PasswordChar = '*';
// Control to allow a max password length of 15 charachers.
textBoxPassword.MaxLength = 15;
}
// This is where the user will re-enter the password for the product owner they wish to add.
private void textBoxConfirmPassword_TextChanged(object sender, EventArgs e)
{
// Each character of the password will display as an asterisk.
textBoxConfirmPassword.PasswordChar = '*';
// Control to allow a max password length of 15 charachers.
textBoxConfirmPassword.MaxLength = 15;
// If statements to ensure that the passwords are the same.
if (textBoxPassword.Text != textBoxConfirmPassword.Text)
{
MessageBox.Show("Passwords do not match.");
textBoxConfirmPassword.Focus();
return;
}
}
在某种程度上它可以正常工作。唯一的问题是,当我开始在确认密码字段中输入时,输入每个字符后都会显示“密码不匹配”消息。我只希望它显示在字符串的末尾。
我确信解决方案很简单,但我正在自学如何使用 Visual,但我找不到答案。
【问题讨论】:
标签: visual-studio visual-studio-2013 passwords