C# Winform 单独文本框默认提示信息

时间:2021-06-24 00:31:32   收藏:0   阅读:38
private string Notes = "提示文本";
private void textBox1_Leave(object sender, EventArgs e)
{
    //  退出失去焦点,重新显示
    if (string.IsNullOrEmpty(textBox1.Text))
    {
        textBox1.ForeColor = Color.DarkGray;
        this.textBox1.Text = Notes;
    }
}
 
private void textBox1_Enter(object sender, EventArgs e)
{
    //  进入获得焦点,清空
    if (textBox1.Text == Notes)
    {
        textBox1.ForeColor = Color.Black;
        this.textBox1.Text = "";
    }
}
此方法只针对提示框未被选中时,在多个文本框在进入时就显示还未解决

  

原文:https://www.cnblogs.com/Sevencodes/p/14924953.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!