Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use AddHandler statement in VB.NET

2024-05-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use AddHandler statements in VB.NET. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Before giving you a detailed introduction to the VB.NET AddHandler statement, let us first understand that the proxy is a class that stores the method index, and then introduce the VB.NET AddHandler statement in a comprehensive way. Events are just used to inform you that an action has occurred. In ObjectARX, we use a reactor (reactor) to handle AutoCAD events. In AutoCAD .NET API, the ObjectARX reactor is replaced with events.

Event handlers (or callback functions) are used to monitor and feedback events that occur in the program. Events can occur in different forms.

Before we introduce events in AutoCAD .NET API, let's take a brief look at proxies.

Agent

A proxy is a class that stores an index of a method (the concept is similar to a function pointer). Proxy pair methods are type safe (similar to function pointers in C #). Proxies have specific forms and return types. Agents can encapsulate any method that conforms to this particular form.

One of the uses of a proxy is to act as a dispatcher for the class that generates the event. Events are objects at the level of * in the .NET environment. Although VB.NET hides many of the details of event handling, events are always implemented by agents. Event agents can be called multiple times (that is, they can store the index of more than one event handling method). They hold a list of registered event handlers for events. A typical agent has the following form:

Public Delegate Event (sender as Object, e as EventArgs)

* the parameter sender represents the object that raised the event.

The second parameter e is an EventArgs parameter (or a derived class), which usually contains data for event handlers.

VB.NET AddHandler statement

To use the event handler, we must associate it with the event. This is done by using the VB.NET AddHandler statement. AddHandler and RemoveHandler allow you to connect, disconnect, or modify handlers associated with events at run time.

When we use the VB.NET AddHandler statement, we determine the name of the event initiator and use the AddressOf statement to determine the event handler, such as:

AddHandler MyClass1.AnEvent, AddressOf EHandler

We said earlier that we would use the RemoveHandler statement to disconnect the event from the event handler (remove the connection). The syntax is as follows:

RemoveHandler MyClass1.AnEvent, AddressOf EHandler, thank you for reading! This is the end of the article on "how to use AddHandler sentences in VB.NET". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report