1.定义事件类:
Public Class clsEvent
Public Event MyEvent1()
Public Event MyEvent2()
Public Sub StartMyEvent1()
RaiseEvent MyEvent1()
End Sub
Public Sub StartMyEvent2()
RaiseEvent MyEvent2()
End Sub
End Class
2.实例化事件对象
Public WithEvents mEventObj As New clsEvent
3.事件响应
Private Sub On_Event1() Handles mEventObj.MyEvent1
Console.WriteLine("Event1")
End Sub
4.触发事件
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
mEventObj.StartMyEvent1()
End Sub
版权声明:本文为博主原创文章,未经博主允许不得转载。