Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create events on dynamic `textboxes`

I managed to create textboxes that are created at runtime on every button click. I want the text from textboxes to disappear when I click on them. I know how to create events, but not for dynamically created textboxes.

How would I wire this up to my new textboxes?

private void buttonClear_Text(object sender, EventArgs e)
{
    myText.Text = "";
}
like image 360
Viva Avatar asked Jan 18 '26 08:01

Viva


1 Answers

This is how you assign the event handler for every newly created textbox :

myTextbox.Click  += new System.EventHandler(buttonClear_Text);
like image 105
Abdusalam Ben Haj Avatar answered Jan 19 '26 20:01

Abdusalam Ben Haj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!