Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a class that contains 5 textboxes. For all of them, the default value is
"Type Here". I want a single mousedown event for all of them that makes the textboxes clear(""). When I create many object for that class and add it to the form there will be many events.

How can I do that with single.
Posted

You can simply subscribe the same event delegate method for all the textBoxes.
C#
this.textBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox_MouseDown);
this.textBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox_MouseDown);

private void textBox_MouseDown(object sender, MouseEventArgs e)
{
  ((TextBox)sender).Clear()
}
 
Share this answer
 
Comments
SS4L84 21-Dec-12 19:40pm    
+5
Jibesh 21-Dec-12 19:41pm    
Thanks friend :)
If these are single line text boxes, you could simply use my CueProvider[^] class.

/ravi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900