我是新手!
下面两种事件声明中事件源在哪里?
再说,下面两个事件声明后如何使用该事件变量的?应用的部位是 changedWorkPhone签名?
那么系统如何识别
Public Event changedWorkPhone
Public Event changedWorkPhone(ByVal newPhone As Long)
------解决方案--------------------
声明:
Public Event changedWorkPhone
Public Event changedWorkPhone(ByVal newPhone As Long)
触发:
RaiseEvent changedWorkPhone
RaiseEvent changedWorkPhone(123456)
事件处理:
类内部:
private sub changedWorkPhone_handler() handles me.changedWorkPhone
end sub
private sub changedWorkPhone_handler(ByVal newPhone As Long) handles me.changedWorkPhone
end sub
类外部:
先声明好一个类的实例,比如
private withevents 实例 as new 你的类名
然后
private sub changedWorkPhone_handler() handles 实例.changedWorkPhone
end sub
private sub changedWorkPhone_handler(ByVal newPhone As Long) handles 实例.changedWorkPhone
end sub
------解决方案--------------------
检查一下你的申明的时候有没有加WithEvents,如private WithEvents 实例 as new 你的类名
------解决方案--------------------
举个例子,比如一个按钮
首先可以声明成Friend WithEvents Button1 As System.Windows.Forms.Button
然后在Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
这样Button1就绑定了事件Button1_Click,也就是Button1.Click就是Button1_Click的事件源。