C#让textBox中显示一些内容,然后鼠标单击进去之后自动清空用MouseClick事件

C#让textBox中显示一些内容,然后鼠标单击进去之后自动清空用MouseClick事件,鼠标单击之后进去将里面的文字清空,但是没有输入文件使用软件的别的功能,怎么让他继续显示出来已经设好的显示内容?

string s = "测试用";
private void Form2_Load(object sender, EventArgs e)
{
this.textBox1.Text = s;
this.textBox1.MouseClick += textBox1_MouseClick;
this.textBox1.Leave+=textBox1_Leave;
}
void textBox1_Leave(object sender,EventArgs e)
{
if (this.textBox1.Text.Trim() == "")
{
this.textBox1.Text =s;
}
}
void textBox1_MouseClick(object sender, MouseEventArgs e)
{
if(this.textBox1.Text.Trim()==s)
{
this.textBox1.Text = "";
}
}

建议用 textBox1.Enter += textBox1_Enter; 这个事件
温馨提示:答案为网友推荐,仅供参考
相似回答