C# Winform 文本框默認提示信息


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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM