基本思路:
1,首先在要定义事件的类中声明事件,然后使用RaiseEvent 激发该事件.
Public Class Person
Private name As String
Public Event walked(ByVal distance As Integer)
Public Sub onwalk(ByVal distance As Integer)
RaiseEvent walked(distance)
End Sub
End Class
2. 使用WithEvents 声明该类的对象.
Friend WithEvents myperson As Person
3,编写事件处理代码.
Private Sub myperson_walked(ByVal distance As Integer) -
Handles myperson.walked
TextBox1.Text = "walked" & distance
End Sub
4,调用事件.
Private Sub Button1_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles Button1.Click
myperson.onwalk(20)
End Sub
1,首先在要定义事件的类中声明事件,然后使用RaiseEvent 激发该事件.
Public Class Person
Private name As String
Public Event walked(ByVal distance As Integer)
Public Sub onwalk(ByVal distance As Integer)
RaiseEvent walked(distance)
End Sub
End Class
2. 使用WithEvents 声明该类的对象.
Friend WithEvents myperson As Person
3,编写事件处理代码.
Private Sub myperson_walked(ByVal distance As Integer) -
Handles myperson.walked
TextBox1.Text = "walked" & distance
End Sub
4,调用事件.
Private Sub Button1_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles Button1.Click
myperson.onwalk(20)
End Sub