1: If an invalid event event is custom, you define yourself to be the memeber class (example from MSDN ):
delegate void Del(int, float); ref class EventReceiver { public: void Handler(int i , float f) { } }; myEventSource->MyEvent += gcnew Del(myEventReceiver, &EventReceiver::Handler);
2: If the main delegate is a global handler and has a standard signature for .NET events (object + event args) (from the DPD answer):
delegate void MyOwnEventHandler(Object^ sender, EventArgs^ e) { } myEventSource->MyEvent += gcnew EventHandler(MyOwnEventHandler);
3: If the main delegate has a standard signature for .NET events, and the event handler is a class method:
ref class EventReceiver { public: void Handler(Object^ sender, EventArgs^ e) { } }; myEventSource->MyEvent += gcnew EventHandler(myEventReceiver, &EventReceiver::Handler);
4: Using System :: EventHandler generic (which takes the args parameter MyEventArgs) as the main delegate:
ref class EventReceiver { public: void Handler(Object^ sender, MyEventArgs^ e) { } }; myEventSource->MyEvent += gcnew EventHandler<MyEventArgs^>(this, &EventReceiver::DataReceived);
Ricibob
source share