VB .NET动态调用control.Validating事件使用反射
对于表单中的每个 Control c,我需要动态发现其 Validating 事件并调用它。
我可以获取事件信息:
Dim ei As EventInfo = c.GetType.GetEvent("Validating")
我可以获取事件列表:
Dim events As System.ComponentModel.EventHandlerList =
CType(c.GetType.InvokeMember("Events", System.Reflection.BindingFlags.GetProperty Or System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic, Nothing, c, Nothing), EventHandlerList)
我尝试过:
Dim fi As FieldInfo = c.GetType.GetField("EventValidating", System.Reflection.BindingFlags.Static Or System.Reflection.BindingFlags.NonPublic)
但 fi 始终是什么都没有。
我无法将它们放在一起并找到事件处理程序然后调用它。
For each Control c in a Form I need to dynamically discover its Validating event and call it.
I can get the event info:
Dim ei As EventInfo = c.GetType.GetEvent("Validating")
I can get the list of events:
Dim events As System.ComponentModel.EventHandlerList =
CType(c.GetType.InvokeMember("Events", System.Reflection.BindingFlags.GetProperty Or System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic, Nothing, c, Nothing), EventHandlerList)
I tried to:
Dim fi As FieldInfo = c.GetType.GetField("EventValidating", System.Reflection.BindingFlags.Static Or System.Reflection.BindingFlags.NonPublic)
But fi is always Nothing.
I can't put these together and find the event handler and then call it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论