Fork me on GitHub

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; }

 

posted @ 2020-10-11 11:30  gentleKay  阅读(4083)  评论(0编辑  收藏  举报