If you check the events for the text box (yellow lightning bold in the Properties pallet) you will see there is a 'Click' event. If you double-click in value space for that event, Visual Studio will stub out a handler for that event that looks something like this (give or take your TextBox's name)
- private void tbMyTextBox_Click(object sender, EventArgs e)
-
{
-
-
}
-
Now that you have a handler method for the Click event you can do what you like, such as clearing the text.
)
- private void tbMyTextBox_Click(object sender, EventArgs e)
-
{
-
tbMyTextBox.Text = string.empty;
-
}
-
Let me point something out though... There is more than one way to enter a text box. You can click in it with a mouse... but you can also tab to it from another control. If you only handle the Click event, then your textbox won't clear if someone tabs into it. If you want to handle either case you might want to worry about the 'Enter' event instead of the 'Click' event.