C # custom controls and events

Source: Internet
Author: User

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 !!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.