事件作为参数的问题

farrio 2006-05-11 04:35:25
我想在一个函数里面,把指定的Event通过AddHandler方法Handle到一个Method上面。
现在我需要把Event作为参数传递进来,但是myEvent As Event报错,没有Event这种数据类型,我用As EventHandler也是不行。

如何把一个Event通过参数传递到函数里面,也就是说这个Event的参数类型是什么呢?
...全文
116 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
sx_lxh 2006-05-12
  • 打赏
  • 举报
回复
传事件委托
class1.a(AddressOf class1.c_testhandler)
不要传事件:
class1.a(class1.Testhandler)
Ninputer 2006-05-12
  • 打赏
  • 举报
回复
在VB里,必须把Event显式声明成某种EventHanlder类型,否则是自动生成的委托类型,本程序的代码无法直接访问。
即你的Event定义要直接As EventHandler,不能直接写参数定义。
sx_lxh 2006-05-12
  • 打赏
  • 举报
回复
Module Module1

Sub Main()
class1.Main()
End Sub

End Module
Public Class class1
Public Delegate Sub test(ByVal m As Integer)
Public Event testhandler As test

Public Sub a(ByVal ta As test)
ta.Invoke(3)
End Sub
Public Sub c_testhandler(ByVal e As Integer)
Console.Write(e)
Console.ReadLine()
End Sub
'<STAThread()> _
Shared Sub Main()
Dim class1 As New class1
AddHandler class1.testhandler, AddressOf class1.c_testhandler
class1.a(AddressOf class1.c_testhandler)
End Sub




End Class
noway8881 2006-05-12
  • 打赏
  • 举报
回复
addhandler myevent,addressof mydelegate?
farrio 2006-05-11
  • 打赏
  • 举报
回复
我知道C#的办法,但是在VB里面,Event好像不是一个Class。
晕,那VB里面的Event到底是个什么东西啊?
farrio 2006-05-11
  • 打赏
  • 举报
回复
最简单来说,我想把AddHandler这个操作封装以下,通过这个函数可以将一个Event和一个Delegate连接在一起。
public sub myaddhandler(myevent as ******, mydetegate as dategate)
addhandler myevent, mydelegate
end sub
zhaoliang_chen 2006-05-11
  • 打赏
  • 举报
回复
Event不可以作为参数
如果需要可以使用属性和委托来解决
sz_lgp 2006-05-11
  • 打赏
  • 举报
回复
address of 或用委托。VB.NET中没有这个东东。
真相重于对错 2006-05-11
  • 打赏
  • 举报
回复
可以用委托
class Class1
{
public delegate void test(int m);
public event test testhandler;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
Class1 c = new Class1();
c.testhandler +=new test(c.c_testhandler);
c.a( c.testhandler );
}
public void c_testhandler(int e)
{}
public void a( test ta )
{
ta(3);
}

}
vb 实在不知怎么写
kssys 2006-05-11
  • 打赏
  • 举报
回复
mark;
楼主不妨讲讲为什么要传Event
HAVENT 2006-05-11
  • 打赏
  • 举报
回复
事件作为参数??晕

从没看过如此用法,你是想传递参数还是想写事件啊

16,556

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧