为避免try-catch块,有没有办法确定控件是否支持指定的事件而没有try-catch块?
Dim d As [Delegate] = [Delegate].CreateDelegate(eventHandler.EventHandlerType, _
Me, _
"OnControlValueChanged") '<<
答案 0 :(得分:2)
使用反射:
Dim events As System.Reflection.EventInfo() = GetType(Control).GetEvents()
For Each someEvent As System.Reflection.EventInfo In events
If someEvent.Name = "OnControlValueChanged" Then
'Do what you need to do
End If
Next