事件参数分配
我有这个事件处理程序
Temp.MouseLeftButtonDown += new MouseButtonEventHandler(Temp_MouseLeftButtonDown);
但我想发送一些参数以在 Temp_MouseLeftButtonDown 函数中访问。 我该如何分配它?
i have this event handler
Temp.MouseLeftButtonDown += new MouseButtonEventHandler(Temp_MouseLeftButtonDown);
but i wanna send some parameter to access in the Temp_MouseLeftButtonDown function.
how can i assign it ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能直接执行此操作,因为事件处理程序只能期望与 MouseButtonEventHandler 兼容的签名。
如果您使用 C# 3,最简单的方法是使用 lambda 表达式 - 类似于:
这有帮助吗?当然,如果您不需要发送者参数和事件参数,则不必提供它们。
在 C# 2 中,您可以以相同的方式使用匿名方法。
You can't do it directly, because the event handler can only expect a compatible signature with MouseButtonEventHandler.
If you're using C# 3, the easiest approach would be to use a lambda expression - something like:
Does that help? Of course, if you don't need both the sender and event args, you don't have to supply them.
In C# 2 you could use an anonymous method in the same way.