Possibility to route different kind of events to only one handler?

  • Thread starter Thread starter Özden Irmak
  • Start date Start date
Ö

Özden Irmak

Hello,

Does anybody know the possibility of routing different kind of events (Which
has different EventArgs like Click and OnPaint for example) to only one
handler sub?

I'm creating a designer control to allow the end users to design a form.The
user can drag new controls into this design surface and after the design I
move those controls to a normal windows form..At this point, I want to get
notified any of the events that those new controls will generate..And I
don't have predefind event subs already in my code which I can link those
controls...

Is there any possibility for this?

Thanks in Advance...

Özden
 
With .NET 2.0 you could use Generics...

But that doesn't help. I can't think of any other way of doing what you're
looking for off hand, although I'm sure you can do something like that with
reflection (I just don't know how without more research)

James Hancock
 
All of the .Net base class event handlers derrive from the same signature.
So you could do something like:

void OnAnyEvent(object sender, EventArgs args)
{
if (args is PaintEventArgs)
{
PaintEventArgs paintArgs = (PaintEventArgs)args;
// do paint specific things
}
}

When you enumerate the events you should probably check the signature
because an event can have any parameters.
 

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

Back
Top