Today, in the project development process, because several pages need to use the same classification control, they want to make it a custom control and then use it with support. I found some columns on the Internet. I don't need to talk about writing custom controls. I mainly talk about how to encapsulate control events into custom events of custom controls. This is also a review of custom events.
The control is composed of the treelist control, followed by the data information found from the data. The question now is how to encapsulate the treelist focusednodechanged event into a custom event.
Rsfocusednodechanged.
First, define the event proxy class
Public class nodes {// <summary> /// selected node // </Summary> Public treelistnode focusednode {Get; set;} public rsfocusednodechangedhandlerargs (treelistnode node) {This. focusednode = node ;}}
Then, you can customize an event and handle the event Delegate:
/// <Summary> /// custom focusenode event // </Summary> public event rsfocusednodechangedhandler rsfocusednodechanged; /// <summary> /// custom delegate for processing the focusenode event /// </Summary> /// <Param name = "sender"> </param> // /<Param name = "E"> </param> Public Delegate void rsfocusednodechangedhandler (Object sender, rsfocusednodechangedhandlerargs E );
Then the execution method between definitions is as follows:
/// <Summary> /// execution event /// </Summary> /// <Param name = "E"> </param> Public void onrsfocusednodechangedhandler (rsfocusednodechangedhandlerargs E) {If (rsfocusednodechanged! = NULL) {rsfocusednodechanged (this, e );}}
Finally, the Custom Event is triggered in the focusednodechanged event of treelist:
Public void treelist1_focusednodechanged (Object sender, devexpress. xtratreelist. Handle e) {// trigger Custom Event Handler = new handler (E. node); onrsfocusednodechangedhandler (ER );}
Done !!