VB.Net 中 WithEvents、AddHandler
发布时间:2020-12-17 00:23:52 所属栏目:大数据 来源:网络整理
导读:[转自] http://www.cnblogs.com/todd/archive/2008/06/20/1226516.html Public Class Form1 Dim WithEvents cls1 As New ClassTest() 'WithEvents方式 Dim cls2 As New ClassTest() 'AddHandler方式 Private Sub Form1_Load(ByVal sender As System.Object,By
[转自]
http://www.cnblogs.com/todd/archive/2008/06/20/1226516.html
Public Class Form1
Dim WithEvents cls1 As New ClassTest() 'WithEvents方式
Dim cls2 As New ClassTest() 'AddHandler方式
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
cls1.Test() 'WithEvents方式
AddHandler cls2.GetValue,AddressOf cls2GetValue 'AddHandler方式
cls2.Test()
Me.Close()
End Sub
Private Sub cls1_GetVale(ByVal str As String) Handles cls1.GetValue 'WithEvents方式
MsgBox("cls1 " & str)
End Sub
Private Sub cls2GetValue(ByVal str As String) 'AddHandler方式
MsgBox("cls2 " & str)
End Sub
End Class
Public Class ClassTest
Public Event GetValue(ByVal str As String)
Public Sub Test()
RaiseEvent GetValue("事件例子")
End Sub
End Class
Result: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
