Reputation: 3092
How to create a Textbox which displays "search" in grey color when it is empty and standard behavior when user starts typing text into it?
Upvotes: 1
Views: 4092
Reputation: 3185
See this thread at MSDN for a possible solution: http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/93a67793-6426-4d4f-be9d-a9b79725efc8
Upvotes: 1
Reputation: 370
Do it via TextBox Events Enter and Leave and Attributes:
private void textBox1_Leave(object sender, EventArgs e)
{
if(textBox1.Text.Trim().Length == 0)
{
textBox1.Text = "Search";
textBox1.ForeColor = Color.LightGray;
}
}
private void textBox1_Enter(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
}
Upvotes: 5