Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 14-May-18 22:30pm
Comments
BillWoodruff 15-May-18 14:06pm    
If it were the case that all the Controla in the new Context had the same names as the Controls in the old context, and those names were distinct, you could work around this.

If this is WinForms, you could also copy Control instantiation data from the Designer.cs file.

In any case you have to know exactly how any Control code in the old context maps to the new Context.

1 solution

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.
 
Share this answer
 
Comments
Primo Chalice 15-May-18 4:32am    
So, I will have to reassign all the events manually?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900