Generic Event Handler

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any generic event arguments which will suffice all type of event
arguments for example I want to capture all the events in the form like this
public sub generalEvent(byval sender as ..., eventarg ...)
control.Mousemove,mouseclick,click etc

Thanks
Sudheendra
 
All custom event arguements must inherit from the EventArgs class, so you can
pass this type to your generic event handler. You'll have to find a way to
determine the specific event that occured to enable you cast the EventArgs
type to the actual type you need in other to access the right
methods/properties of the event args.

public sub generalEvent(object sender, EventArgs e)
{
}

Hope this helps...
 
Kingsley said:
All custom event arguements must inherit from the EventArgs class,

No - It's only a convention. Events can have any delegate type whatsoever.
 
Plus, I may be mistaken but I think the signature of the event handling
routine must match the delegate precisely - it can't just use the basic
EventArgs class as it's second parameter if it's going to handle (for
example) the MouseDown event (which requires a subclass of MouseEventArgs or
something like that).
 
Plus, I may be mistaken but I think the signature of the event handling
routine must match the delegate precisely - it can't just use the basic
EventArgs class as it's second parameter if it's going to handle (for
example) the MouseDown event (which requires a subclass of MouseEventArgs or
something like that).

I may be wrong, but isn't this allowed in dot net 2.0?
 
Back
Top