实现类person
包括成员变量 dbdistance
方法 work()用raiseevent 触发事件
并用event申明一个事件 worked
Public Class person
Public dbdistance As Double
Public Event walked(ByVal distance As Double)
Public Function work(ByVal distance As Double) As Double
dbdistance += distance
RaiseEvent walked(distance)
Return dbdistance
End Function
End Class
类事例化并调用
Private person As New person
事件处理过程
Sub work(ByVal distance As Double) Handles person.walked
MessageBox.Show("zou le" & distance)
End Sub
动态邦定事件与事件处理过程
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler person.walked, AddressOf work
End Sub
次例中用到addhandler,addressof 来实现事件与事件处理过程的动态绑定
————————————————
版权声明:本文为CSDN博主「qisir1981」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qisir1981/article/details/1222571