如何使用C#中的事件创建引用? [英] How do I create a reference with events in C#?

查看:105
本文介绍了如何使用C#中的事件创建引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



实际上,我有一个旧项目,它有很多活动。我以新的形式复制并粘贴了代码,现在没有任何事件正在运行,因为没有任何事件连接到各自的控件。



我有什么方法可以将所有事件连接到各自的控件?有很多活动,所以手工工作需要很多时间。



Reagrds

Aman Chaurasia



我尝试了什么:



我一直试图手动完成它但是它正在服用很多时间。我必须复制每个事件代码并在创建新事件后将其粘贴到新表单中。

Hello,

Actually, I had an old project and it had numerous events. I copied and pasted the codes in a new form and now none of the events are working as none are connected to their respective controls.

Is there any way that I can connect all the events to their respective controls? There are a lot of events, so manual work will take a lot of time.

Reagrds
Aman Chaurasia

What I have tried:

I have been trying to do it manually but it is taking a lot of time. I have to copy each event code and paste it in the new form after creating a new event.

推荐答案

否:因为除非控件名称和类型相同系统无法知道哪个事件应该挂钩到哪个控件,以及该事件的处理程序。请记住,处理程序可以是通用的:它可以使用相同的代码处理多个控件的事件,因此处理程序的名称可能不会反映源控件或它的事件。
No: because unless the control names and types are the same there is no way for the system to know which event should be hooked to which control, and which handler to that event. Remember, a handler can be generic: it can process events for a number of controls with the same code, so the name of the handler may not reflect the source control or it's event at all.


这篇关于如何使用C#中的事件创建引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆