Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retain Event handler assignments when cutting and pasting WinForms controls in VS2012 C# project?

Is there a way to maintain the Event handler assignments when cutting and pasting controls in the VS2012 designer? For example, I have a graph control that has a Load event with code in the Event stub. If I cut and paste the graph control, the Load event no longer shows as having an Event handler assignment in the Properties Editor. I have to use the drop-down box next to the Load event to reselect my existing Event handler code for the Load event (redo the assignment). Is there a way to cut and paste controls without losing the Event handler assignments?

In Delphi I could just cut and paste controls freely and the event handler assignments were part of the clipboard text so they were retained when a control was pasted onto a form or frame. I am hoping there is a way to do the same with Visual Studio 2012 and a C# project.

like image 863
Robert Oschler Avatar asked Feb 02 '13 02:02

Robert Oschler


2 Answers

You need to use the Document Outline

View > Other Windows > Document Outline

And find your desired control and then drag and drop it to target container. In this case you wont miss any events.

like image 53
Mohammad Gohari Avatar answered Oct 06 '22 00:10

Mohammad Gohari


When you cut or copy a control using the Visual Studio designer only the properties of the controls are copied. This is by design and in my opinion, is justified. It would be counter intuitive most of the time if you where copying a control and all of the same event handlers where assigned or copied over.

It sounds like the control is remaining in the same Form. In which case dragging and placing the control should suffice for the most part.

like image 35
User 12345678 Avatar answered Oct 06 '22 00:10

User 12345678