C# 设置TextBox默认显示文字,点击后消失

     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; }
原文地址:https://www.cnblogs.com/strive-19970713/p/13796701.html