The events in the control.

Source: Internet
Author: User
First, let's take a look at several classes and attributes related to events and delegation:
Delegate, multicastdelegate, eventhandler, eventhandlerlist, eventhandlerlist. listentry, control, component

The events attribute of control is inherited by system. componentmodel. component, which is an instance of eventhandlerlist.

The eventhandlerlist class has three important methods:

Public   Void Addhandler ( Object Key, delegate value );
Public   Void Removehandler ( Object Key, delegate value );
Private Listentry find ( Object Key );

Example: we want to add a click event for the current control ).
Step 1: Create a static read-only attribute
Public static readonly object clickevent = new object (); // It is the key (key) for future event search delegation ),
Step 2: register an event
Public event eventhandler click
{
Add
{
Base. Events. addhandler (clickevent, value );
}
Remove
{
Base. Events. removehandler (clickevent, value );
}
}
----
The following is the definition of events: Private Eventhandlerlist events;
Protected Eventhandlerlist events
{
Get
{
If ( This . Events =   Null )
{
This. Events= NewEventhandlerlist ();
}
Return   This . Events;
}
}

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.