If I create multiple instances of a class which has an event associated with it and add them to a colletion, how do I know which instance triggered the event?
The "sender" argument to the event handler is ALWAYS the object that raised the event. It is of type Object though so you need to cast it as the correct type. If this is an event of your own creation that is a member of the collection itself then you would need to create your own class that inherits EventArgs class and give it a property that refers to the item that raised the event, just like the ToolBar.ButtonClick event handler takes a ToolBarButtonClickEventArgs object that has a Button property that indicates which butoon was clicked.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.