1.先在目标文本框中放置一个label,然后在窗体的代码页中添加标签初始化的方法:
public void loadRegister()
{
lbelPaswrd.Text = "长度不得低于6位";
lbelPaswrd.ForeColor = Color.Gray;
Font MyFont = new Font("宋体", 9, FontStyle.Italic);
lbelPaswrd.Font = MyFont;
}
然后在窗体的Load事件中添加该方法;
2.在该label的属性页双击MouseDown事件,然后在代码设计器中添加如下代码:
private void lbelPaswrd_MouseDown(object sender, MouseEventArgs e)
{
lbelPaswrd.Visible = false;
tBoxRPasWd.Focus();
}
tBoxRPaswd就是装label的目标文本框。
3.在目标文本框的Leave事件中添加如下代码:
private void tBoxRPasWd_Leave(object sender, EventArgs e)
{
if (tBoxRPasWd.Text == string.Empty)
lbelPaswrd.Visible = true;
}
4.运行程序,看是否达到效果
我自己用这个方法达到了目的,所以这个方法应该有效。