将Control的EventHandler复制到另一个(Copy EventHandler of a Control to another)

编程入门 行业动态 更新时间:2024-10-19 00:29:54
Control的EventHandler复制到另一个(Copy EventHandler of a Control to another)

我有一个Button(button1),如何将它的Click属性(我的意思是button1.Click)复制到另一个Button(button2),如:

button2.Click=button1.Click;

I have a Button (button1) , How can I copy it's Click property (I mean button1.Click) to another Button (button2), Something like:

button2.Click=button1.Click;

最满意答案

你不可以做这个。 事件只允许您添加或删除处理程序,您无法获得他们拥有的所有处理程序的列表。 这是一个故意从您身上移除的功能。

您可以独立地跟踪自己分配给特定按钮的处理程序,然后将这些处理程序添加到另一个按钮,以实现此效果。

You cannot do this. Events only allow you to add or remove handlers, you cannot get a list of all of the handlers that they have. It is a function that is intentionally removed from you.

You could keep track of the handlers you assign to a particular button yourself, independently, and then add those handlers to another button, to accomplish this effect.

更多推荐

本文发布于:2023-04-28 05:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1330318.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Control   EventHandler   Copy

发布评论

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

>www.elefans.com

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