开发者

Using reflection to determine if a control supports an event

To avoid the try-catch block, is there a way to determine if a control supports the specified event without having a try-catch block?

Dim d As [Delegate] = [Delegate].CreateDelegate(eventHandler.EventHandlerType, _
                                                                Me, _
              开发者_运维知识库                                                  "OnControlValueChanged") '<<


Use reflection:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜