WinForms/.NET:如何获取附加到事件的事件处理程序?
如何将事件处理程序附加到事件?
伪代码,例如:
public static EventHandler GetChangeUICuesEventHandler(Control SomeControl)
{
EventHandler changeUICuesEventHandler = SomeControl.ChangeUICues;
return changeUICuesEventHandler
}
示例用法(伪代码):
Control control = GetControlByName(Console.ReadLine());
button1.ChangeUICues += GetChangeUICuesEventHandler(control);
How can i get the event handler attached to an event?
pseudocode, for example's sake:
public static EventHandler GetChangeUICuesEventHandler(Control SomeControl)
{
EventHandler changeUICuesEventHandler = SomeControl.ChangeUICues;
return changeUICuesEventHandler
}
Sample usage (pseudo-code):
Control control = GetControlByName(Console.ReadLine());
button1.ChangeUICues += GetChangeUICuesEventHandler(control);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我提供以下内容作为替代路径而不是直接答案...所以这里...
您可以通过确保您的控件已附加事件处理程序(在本例中为参数
someControl,而是实现一个定义附加处理程序的接口。例如:
那么你可以像这样使用它:
I offer up the following as an alternative path rather than a direct answer... So here goes...
Can you approach this a little differently perhaps by ensuring that your control with the event handler already attached, in this case the parameter
someControl
, instead implements an interface that defines the attached handler. For example:Then you could use it like so: