Q上输入账号密码的时候会有一个提示信息,这个是如何实现的呢?
正文
//用户名自动提示 private void txtUserID_Enter(object sender, EventArgs e) { txtUserID.Focus(); txtUserID.Text = "请输入用户名"; txtUserID.ForeColor = Color.LightGray; } private void txtUserID_Leave(object sender, EventArgs e) { if (txtUserID.Text == "") { txtUserID.Text = "请输入用户名"; txtUserID.ForeColor = Color.LightGray; } } //点击用户文本框,内容清空 private void txtUserID_MouseClick(object sender, MouseEventArgs e) { txtUserID.Text = ""; } private void txtPassWord_MouseClick(object sender, MouseEventArgs e) { txtPassWord.Text = ""; } //密码自动提示 private void txtPassWord_Enter(object sender, EventArgs e) { txtPassWord.Text = "请输入密码"; txtPassWord.ForeColor = Color.LightGray; } //离开自动回复密码提示 private void txtPassWord_Leave(object sender, EventArgs e) { if (txtPassWord.Text == "") { txtPassWord.Text = "请输入密码"; txtPassWord.ForeColor = Color.LightGray; } } //密码框为* private void txtPassWord_TextChanged(object sender, EventArgs e) { if (txtPassWord.Text == "" && txtPassWord.Text != "请输入密码") { txtPassWord.PasswordChar = Convert.ToChar("*"); } }
小结
这个功能逻辑有点绕,还需要再研究一下。