An event is only used to notify an action that has occurred. In ObjectARX, we use reactor to Process AutoCAD events. In the AutoCAD. net api, the ObjectARX reactor is replaced with an event.
An event handler or callback function is used to monitor and feedback events in a program. Events can appear in different forms.
The following describes the Proxy:
Proxy is a class that stores method indexes. Its concept is similar to that of function pointers ). The proxy method is type-safe and similar to the function pointer in C ). The proxy has a specific form and return type. The proxy can encapsulate any method that meets this specific form.
A proxy is used as the class distributor that generates events. An event is the first-level object in the. NET environment. Although VB. NET hides many details of event processing, events are always implemented by proxies. Event proxies can be called multiple times to store indexes of more than one event processing method ). They save a list of registration events for processing events. A typical proxy has the following forms:
Public Delegate Event (sender as Object, e as EventArgs)
The first parameter sender indicates the object that triggers the event.
The second parameter e is an EventArgs parameter or a derived class). This object usually contains data used for event processing functions.
VB. NET AddHandler statement
To use the event handler function, we must associate it with the event. This requires the use of the VB. NET AddHandler statement. AddHandler and RemoveHandler allow you to connect, disconnect, or modify the processing functions associated with the event at runtime.
When we use the VB. NET AddHandler statement, we need to determine the name of the event initiator and use the AddressOf statement to determine the event processing function. For example:
AddHandler MyClass1.AnEvent, AddressOf EHandler
We mentioned earlier that the RemoveHandler statement should be used to disconnect the event from the event handler function ). The syntax is as follows:
RemoveHandler MyClass1.AnEvent, AddressOf EHandler
This article from the "Growing Years" blog, please be sure to keep this source http://3753512.blog.51cto.com/3743512/1206881