如何在类库 (DLL) 上声明事件并在表单上捕获它们? [英] How to declare events on a class library (DLL) and catch them on a form?
本文介绍了如何在类库 (DLL) 上声明事件并在表单上捕获它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在类库上设置事件并在表单中捕获它们.
I need to set events on a class library and catch them in an form.
例如,我在 DLL 文件中运行一个子程序,我需要接收"类中的子程序正在运行的事件.
For example, I run a sub in the DLL file, and I need to "receive" the event that the sub in the class is running.
DLL 文件是我在 Visual Basic 中创建的,但我如何在其上引发事件以在表单中捕获?
The DLL file is created by me in Visual Basic, but how do I raise events on it to be catched in the form?
请举例说明.
推荐答案
dll中的代码
Public Event MySpecialEvent ()
Private Sub Test
RaiseEvent MySpecialEvent
End Sub
表单中的代码
Private _MyDll as MyDLL
Public Sub Main
_MyDLL = New MyDLL
AddHandler _MyDLL.MySpecialEvent, AddressOf MySpecialEventHandler
End Sub
Private Sub MySpecialEventHandler
'Put your code here to act upon the handled event
End Sub
您还需要在表单生命周期中的某个时刻删除事件处理程序
You'll also need to remove the event handler at some point in the form's life with
RemoveHandler _MyDLL.MySpecialEvent, AddressOf MySpecialEventHandler
这篇关于如何在类库 (DLL) 上声明事件并在表单上捕获它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文