I think you want to show the default Text
of a textbox, if it's just focused without any editing, the default Text
will be restored when it loses focus like this:
string initText = "Love .NET";
bool edited;
//This code line is just for demonstrative purpose, it should be placed such as in the Form constructor
textBox1.Text = initText;
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
edited = !char.IsControl(e.KeyChar);
}
private void textBox1_Enter(object sender, EventArgs e)
{
if(!edited) textBox1.Clear();
}
private void textBox1_Leave(object sender, EventArgs e)
{
if (!edited) textBox1.Text = initText;
}
If you want to make the text look like watermark
, you may want to apply more Font
and ForeColor
accordingly or some custom Paint if needed. The last is using a third-party textbox, it's up to you.