Find all event handlers for a Windows Forms control in .NET

后端 未结 3 1038
余生分开走
余生分开走 2020-12-20 03:24

Is there a way to find all event handlers for a Windows Forms control? Specifically statically defined event handlers?

3条回答
  •  悲&欢浪女
    2020-12-20 03:51

    Windows Forms has strong counter-measures against doing this. Most controls store the event handler reference in a list that requires a secret 'cookie'. The cookie value is dynamically created, you cannot guess it up front. Reflection is a backdoor, you have to know the cookie variable name. The one for the Control.Click event is named "EventClick" for example, you can see this in the Reference Source or with Reflector.

    This is all incredibly unpractical, if you're getting the feeling you are doing something unwise then you're on the right track. You can find sample code that does this in my answer in this thread.

提交回复
热议问题