问题
Do I always need to use a delegate / Eventhandler to get to the data stored within a custom EventArgs class or can I access it directly?
回答1:
A custom EventArgs
class is just like any other class. If you have an instance of it, you can access it's (visible) members.
Typically, however, EventArgs
is only used in conjunction with events, and you need a delegate to subscribe to an event. As such, it would normally be used (from the consumption side) with some form of delegate, though this could just be a delegate referencing a standard method where you use the EventArgs
subclass.
回答2:
I don't think you can access a custom eventArgs class just like another class. I believe it needs to be within a Delegate that returns the data properly... I have tried to access the custom event args class directly from within any event (including a button) and it has been fruitless...
See my follow up question:
how to access Custom EventArgs class in Button click event?
来源:https://stackoverflow.com/questions/5399770/access-values-within-custom-eventargs-class