如何才有可能删除“按钮”的“点击”事件的所有事件处理程序?

编程入门 行业动态 更新时间:2024-10-11 03:21:44
本文介绍了如何才有可能删除“按钮”的“点击”事件的所有事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个按钮控制,而且我需要删除所有连接到它的单击事件。

怎么会是这样可能吗?

按钮按钮= GetButton(); button.Click.RemoveAllEventHandlers();

解决方案

您不能,基本上 - 至少不是没有思考和大量grubbiness的

活动都严格订阅,退订。 - 你不能退订别人的处理程序,任何比你更可以改变别人的对象引用

I have a button control, and I'd need to remove all the event handlers attached to its Click event.

How would that be possible?

Button button = GetButton(); button.Click.RemoveAllEventHandlers();

解决方案

You can't, basically - at least not without reflection and a lot of grubbiness.

Events are strictly "subscribe, unsubscribe" - you can't unsubscribe someone else's handler, any more than you can change someone else's reference to an object.

更多推荐

如何才有可能删除“按钮”的“点击”事件的所有事件处理程序?

本文发布于:2023-11-02 10:05:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552089.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   才有   按钮   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!