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 implement event triggering in VB.NET

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you "VB.NET how to achieve event trigger", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "VB.NET how to achieve event trigger" this article.

Events in VB.NET are a very important concept. For beginners, we must pay attention to this aspect in the process of learning.

Event

In VB.NET, inheritance is fully supported for VB.NET events. If a base class defines a Public event, the event can be triggered by the code of the base class or any subclass inherited from the base class.

For example, we can first define a base class with the following code:

Public Class Parent Public Event ParentEvent () Public Sub DoEvent () RaiseEvent ParentEvent () End Sub End Class

Obviously, the code in the class can trigger the ParentEvent event. We can also create a subclass like this:

Public Class SubClass Inherits Parent Public Sub DoSomething () RaiseEvent ParentEvent () End Sub End Class

This subclass is inherited by using the Inherits keyword, which not only gets the properties and methods of the parent class, but also inherits the events of the base class.

The VB.NET event can define any scope. If defined as a Private event, it can only be obtained by sending an object, but the Public event can be accessed by any object. Protected events can be accessed by defining classes or subclasses to create objects. In addition, Friend events can be accessed by any object in the VB.NET project.

Unlike methods, events cannot be overloaded using the Overloads keyword. A class can define an event with any specific name. Because any subclass will automatically retrieve the event from the parent class, all Override keywords appear to be useless and cannot be used in the event.

Shared event

The VB.NET event can be defined as Shared. A shared method can trigger shared events, but not non-shared events, as shown in the following example:

Public Class EventSource SharedEvent SharedEvent () Public Shared Sub DoShared () RaiseEvent SharedEvent () End Sub End Class

A shared event can also be triggered by a shared or non-shared method. Here is an example:

Public Class EventSource Public Event TheEvent () SharedEvent SharedEvent () Public Sub DoSomething () RaiseEvent TheEvent () RaiseEvent SharedEvent () End Sub Public Shared Sub DoShared () RaiseEvent SharedEvent () End Sub End Class

If you want to trigger a non-shared event from a shared method, it will result in a syntax error.

The above is all the content of the article "how to achieve event triggering in VB.NET". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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