Adding a function call to an event dynamically

V

Vince Panuccio

Hello

I know how to loop through all the controls on a form, but what id
like to do as Im looping is (depending on the control), add a function
i've written to an event of that control.

For example, If during the loop I encounter a textbox control, how
would I add my foobar() function call to the TextChanged event?

Is this possible?

Thanks
 
V

Vince Panuccio

Hi Vince,


function call to the TextChanged event

E.g.
if (control is TextBox)
{
control.TextChanged += foobar;

}

using

void foobar(object sender, EventArgs e) { ... }

Alexhttp://devkids.blogspot.com

Thanks Alex, didn't know if was that easy :)
 
H

Herfried K. Wagner [MVP]

Vince Panuccio said:
I know how to loop through all the controls on a form, but what id
like to do as Im looping is (depending on the control), add a function
i've written to an event of that control.

For example, If during the loop I encounter a textbox control, how
would I add my foobar() function call to the TextChanged event?

If you are using VB.NET, check out the 'AddHandler' statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top