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

时间:2020-11-12 13:47:03   收藏:0   阅读:21
     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; }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!