C# 设置TextBox默认显示文字,点击后消失
2020-12-18 15:38
标签:black leave obj bsp else als ast class 默认 C# 设置TextBox默认显示文字,点击后消失 标签:black leave obj bsp else als ast class 默认 原文地址:https://www.cnblogs.com/strive-19970713/p/13796701.html Boolean textboxHasText = false;//判断输入框是否有文本
//触发两个事件
//textbox获得焦点
private void Textbox_Enter(object sender, EventArgs e)
{
if (textboxHasText == false)
Textbox.Text = "";
Textbox.ForeColor = Color.Black;
}
//textbox失去焦点
private void Textbox_Leave(object sender, EventArgs e)
{
if (Textbox.Text == "")
{
Textbox.Text = "提示内容";
Textbox.ForeColor = Color.LightGray;
textboxHasText = false;
}
else
textboxHasText = true;
}
文章标题:C# 设置TextBox默认显示文字,点击后消失
文章链接:http://soscw.com/index.php/essay/37118.html