how to write custom event handling classes, if any one having idea about how to create it or if you know any good article regarding this then please help me.
Thanks in Advance
Steps of Event CreationCreate a delegate, which holds the details of the subscribers to an event. Create a public event that is externally visible to the class and used for creating subscriptions. Create the method in the class, which will fire the event itself.
EventArgs e is a parameter called e that contains the event data, see the EventArgs MSDN page for more information. Object Sender is a parameter called Sender that contains a reference to the control/object that raised the event.
AssemblyLoadEventArgs class derives from EventArgs and is used to hold the data for assembly load events. To create a custom event data class, create a class that derives from the EventArgs class and provide the properties to store the necessary data. The name of your custom event data class should end with EventArgs .
I'm not entirely sure what you mean, but if you're talking about an EventArgs derived class:
public class MyEventArgs : EventArgs
{
private string m_Data;
public MyEventArgs(string _myData)
{
m_Data = _myData;
} // eo ctor
public string Data {get{return m_Data} }
} // eo class MyEventArgs
public delegate void MyEventDelegate(MyEventArgs _args);
public class MySource
{
public void SomeFunction(string _data)
{
// raise event
if(OnMyEvent != null) // might not have handlers!
OnMyEvent(new MyEventArgs(_data));
} // eo SomeFunction
public event MyEventDelegate OnMyEvent;
} // eo class mySource
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With