Four steps for C # events

xiaoxiao2021-03-06  21

.NET definition event requires some rules of the conventional bundle:

The event function is provided by three interconnected elements: providing class, event delegate, and classes of events. The .NET Framework has an agreement with a class and method related to the event. If you want your class to trigger an event called EventName, you need the following elements.

The class of incident data is named EventNameEventArgs. This class must be exported from tabindex = "0" keywords = "fr1rfsystemEventArgsclasstopic" /> system.eventargs. The commission of events is called EventNameEventHandler. Start the class of events. This class must provide:

Event declaration. [C #]

Public Event EventNameEventHandler EventName; Method for causing events, named OneventName.

The .NET Framework class library or third-party library may have defined event data classes and event commission classes. In this case, you don't need to define these classes.

If you are not familiar with the entrustment model of the event in .NET Framework, see Events and Benefits.

Declaration event

Public Event EventnameEventHandler EventName

2. Declaration agency;

Public Delegate Void EventNameEventHandler (Object Sender, EventnameEventArgs E);

3. Define method

Void EventHandler (Object Sender, EventNameEventArgs E) {}

4. Trigger events

For example, on_click = on server control

转载请注明原文地址:https://www.9cbs.com/read-43216.html

New Post(0)