Custom events (if not described, C # code is used in this blog document)

Source: Internet
Author: User
1 // Define proxy
2 Public   Delegate   Void Connectionerrordelegate (connectionstatus status, String MSG );
3 // Define proxy events
4 Public   Event Connectionerrordelegate connectionerrorevent;
5 // Define proxy object
6 Private Connectionerrordelegate Deleg =   Null ;
7 // Define proxy Methods
8 Deleg =   New Connectionerrordelegate (service_connectionerrorevent );
9 // Proxy events that assign a proxy object to a service object
10 Service. connectionerrorevent + = Deleg;
11 // Trigger this event
12 Connectionerrorevent (status, errmsg );

First, let's take a look at the analysis. Previously, we often used established proxies and events. What we want to do is to instantiate the proxy object, that is, the methods that really need to be executed, proxy events, and proxy have long been in.. NET component. For the Click Event of the button
What we see in the designer is this. button1.click + = new system. eventhandler (this. button#click );
Among them, eventhandler // Abstract:
// Indicates the method to process events that do not contain event data.
[Serializable]
[Comvisible ( True )]
Public   Delegate   Void Eventhandler ( Object Sender, eventargs E );

While this. button1.click is

//
// Abstract:
// It occurs when you click the control.
Public   Event Eventhandler click;

Now we understand that what we need to do is to define a method with the same parameters as the proxy. We can give the proxy method entry to the event and click the button.
When you click a button, the click (boject, E. empter); method should be generated. The parameters here are gibberish, which is probably the parameters of the mouse.
The specific idea is this. If you don't understand anything, you can add my group chat.

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.