关于winform登录窗体的文本框问题

设置TextBox控件的默认文本即在加载TextBox控件时为其Text文本赋值。点击文本消失,离开或者失去焦点显示默认文本可以通过Enter和Leave事件或Mouse的事件来实现。具体代码如下。 

private void txtPassword_Enter(object sender, EventArgs e)
{
pnlPassword.BackgroundImage = ImageHelper.GetImage("Login\\login_account_focus.png");
pnlAccount.BackgroundImage = ImageHelper.GetImage("Login\\login_account_default.png");

if (txtPassword.Text.Trim() == "请输入密码")
{
txtPassword.ForeColor = ColorTranslator.FromHtml("#333333");
txtPassword.Text = "";
txtPassword.PasswordChar = '*';
}
}

private void txtPassword_Leave(object sender, EventArgs e)
{
pnlPassword.BackgroundImage = ImageHelper.GetImage("Login\\login_account_default.png");

if (txtPassword.Text.Trim().Length == 0)
{
txtPassword.ForeColor = ColorTranslator.FromHtml("#999999");
txtPassword.PasswordChar = '\0';
txtPassword.Text = " 请输入密码";
}
}

猜你喜欢

转载自www.cnblogs.com/q240722328/p/9692142.html