将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.
更多推荐
发布评论