C# TextBox 控件添加提示
//Lostfocus当一个控件失去焦点时触发,定义控件失去焦点时的方法 this.textBox1.LostFocus += new System.EventHandler(this.textBox1_LostFocus); //GotFocus是在一个对象得到焦点时发生,定义控件得到焦点时的方法 this.textBox1.GotFocus += new System.EventHandler(this.textBox1_GotFocus);
1 private void txtHospitalSearch_GotFocus(object sender, EventArgs e) 2 { 3 txt.Text = ""; 4 txt.ForeColor = Color.Black; 5 } 6 private void txtHospitalSearch_LostFocus(object sender, EventArgs e) 7 { 8 txt.Text = "我是提示哦"; 9 txt.ForeColor = Color.Gray; 10 }