http://blog.csdn.net/uuxyz/article/details/7175248
EventHandler delegate with custom delegate
Custom Delegate:
//1. Public Delegate voidUcsavedeventhanler (BOOLissuccess); //2. Public EventUcsavedeventhanler onucsaved; //3.UcEditor1 (user control). onucsaved+=NewUcsavedeventhanler (uceditor1_onucsaved); voidUceditor1_onucsaved (BOOLissuccess) { //TODO:}
EventHandler Commission:
//2.1. Public EventEventHandler onucsaved;//2.2. Public classsavedeventargs:eventargs{ PublicSavedeventargs (BOOLissuccess) { This. issuccess=issuccess; } Public BOOLissuccess; }//end of class Savedeventargs//3.UcEditor1 (user control). onucsaved+=NewEventHandler (uceditor1_onucsaved);voidUceditor1_onucsaved (ObjectSender,eventargs e) { //TODO:}
1:eventhandler is actually a special delegate, it is made up of. NET is a predefined delegate, and its form is fixed . The definition of EventHandler is similar to the following:
delegate void EventHandler(Object Sender,eventargs e);
such as the Click event
New EventHandler (But_click); void But_click (object sender, EventArgs e) { //Todo}
2: When using EventHandler, the return value of the handler function must be of type void, while using deleagate does not have this restriction.
3:delegate is equivalent to a pointer to a function that is used to bind the function return value and the parameter list to conform to the requirements of the delegate declaration.
EventHandler delegate with custom delegate