我正在为我的程序创建一个登录表单,其中我有两个文本框电子邮件和密码的水印.
当文本框为空时,其水印文本将显示在其中,如"在此处输入电子邮件"和"在此输入密码".
到目前为止我的代码是:
private void emailLogin_Leave(object sender, EventArgs e){
if (emailLogin.Text.Length == 0){
emailLogin.Text = "Email";
emailLogin.ForeColor = Color.Silver;
}
}
private void emailLogin_Enter(object sender, EventArgs e){
if (emailLogin.Text == "Email"){
emailLogin.Text = "";
emailLogin.ForeColor = Color.Black;
}
}
private void passwordLogin_Leave(object sender, EventArgs e){
if (passwordLogin.Text.Length == 0){
passwordLogin.Text = "Password";
passwordLogin.ForeColor = Color.Silver;
}
}
private void passwordLogin_Enter(object sender, EventArgs e){
if (passwordLogin.Text == "Password"){
passwordLogin.Text = "";
passwordLogin.ForeColor = Color.Black;
}
}
Run Code Online (Sandbox Code Playgroud)
但现在我的问题是我想使用密码字符作为密码.但我仍然希望水印文本是常规文本.当我检查使用密码char时,它会将我的水印变为" ** "而不是"密码".我该如何解决这个问题?
顺便说一下,我不想使用"UseSystemPasswordChar"(那些点).我想使用"PasswordChar"并使用星号(*)作为密码字符.
只需设置它并取消设置就像对ForeColor一样:
private void passwordLogin_Leave(object sender, EventArgs e){
if (passwordLogin.Text.Length == 0){
passwordLogin.Text = "Password";
passwordLogin.ForeColor = Color.Silver;
passwordLogin.PasswordChar = '\0';
}
}
private void passwordLogin_Enter(object sender, EventArgs e){
if (passwordLogin.Text == "Password"){
passwordLogin.Text = "";
passwordLogin.ForeColor = Color.Black;
passwordLogin.PasswordChar = '*';
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
778 次 |
| 最近记录: |