In my app I have a 85 textboxes. All textboxes in my app like this :
void textBox1s(string input)
{
this.textBox1.ForeColor = Color.Black;
this.textBox1.Text = input;
}
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
textBox1s(Clipboard.GetText());
}
and now I want any textbox when checkbox is checked by Click/MouseClick on textbox1 >>>only empty textbox1.text
if click on textbox2 >>> only empty textbox2.text
and …..
and in my app i have tabControl1 and 18 groupbox
how can set all textbox when checkbox is checked for empty by Click/MouseClick on textbox ?
if my answer is use user control please give me 1 sample code
Thanks.
neurotix was heading down the right track, but that won’t catch your textboxes in child containers, nor will it handle calling the right function, to set the right textbox’s properties. best way to handle it without an user control is to use a recursive function to assign your event handler.
If you use an user control, that’s really easy, just inherit from TextBox, and set everything to use the new control.
I recommend creating the customer user control for the following reasons:
Of course, if all you need to do, is set the text, and nothing else in that function, you could simplify it a bit…
or using the user control:
For many of the above reasons, I’d still recommend the custom user control.