Capturing Event
-
Is there is any way to handle events of different types by one function. For example I want to handle events of EventHandler type and my custom events with single function that have different number of parameters or have no parameters.
You can add a handler to several different events, but if you need to determine where the event came from or what type of event it was, you have to check the values of the sender and eventargs parameters sent to the event handler. An event handler has to be declared with the exact parameters as the eventhandler delegate, e.g. with the sender and eventargs parameters. From the event handler you can then call any methods you wish in your code. --- b { font-weight: normal; }
-
You can add a handler to several different events, but if you need to determine where the event came from or what type of event it was, you have to check the values of the sender and eventargs parameters sent to the event handler. An event handler has to be declared with the exact parameters as the eventhandler delegate, e.g. with the sender and eventargs parameters. From the event handler you can then call any methods you wish in your code. --- b { font-weight: normal; }
The Problem is that I cannot use only eventhandler delegate. I am using Infragistics controls and For example i cannot add same function to Button.Click and Infragistics.Win.UltraWinEditors.UltraTextEditor.EditorButtonClick because it has type EditorButtonEventHandler. Maybe there is any way to handle such event using reflection?
-
The Problem is that I cannot use only eventhandler delegate. I am using Infragistics controls and For example i cannot add same function to Button.Click and Infragistics.Win.UltraWinEditors.UltraTextEditor.EditorButtonClick because it has type EditorButtonEventHandler. Maybe there is any way to handle such event using reflection?
You need at least one event handler for each type of delegate. The event basically uses a reference to the handler to call it, and if the parameters that the handler accepts does not match the parameters that the event sends, you would mess upp the stack. Maybe you could add a event handler reference of the wrong type to the event using reflection, but that would probably just crash the application. --- b { font-weight: normal; }