0

I was strangling with the layout on my windows c# app form and I cut some textBoxes, listBoxes, Buttons, etc and pasted them with the exact same name. Now if I dubble click the button, it won't refer to the code from the previous button but instead calls the new method:

"ButtonName"_Click_1(object sender, EventArgs e)

I'm talking about allot of layout, probably around 60 controls and recreating that takes so much time.

Could I undo these changed, or make them work? Or maby restore to an earlier version of the solution/classes?

edit: Could it only be the buttons which wont refer to the code or also all textboxes and other controls?

Nick Peelman
  • 585
  • 1
  • 10
  • 28
  • Do you have your code in a Version Control System? If so, just revert your changes. – jrummell Apr 08 '13 at 17:05
  • Unless you used source control/version control, you're hosed. You need to manage your code better. Based on the problem you mentioned, you just need to get into the xaml and look at the click event for that button and set it to the method you want. – tnw Apr 08 '13 at 17:06
  • 4
    Unless it's still open (and you can just hit Undo), or you're using a version control system (or have some other type of backup), you're out of luck. That's why you should always use a VCS, [even if you're the only developer](http://stackoverflow.com/a/3868455/298754). – Bobson Apr 08 '13 at 17:06
  • 1
    Also, WPF or WinForms? – Bobson Apr 08 '13 at 17:10
  • If you mean back-up programs by version system control; I have nothing backuped about visual studio :/ – Nick Peelman Apr 08 '13 at 17:10
  • WinForms c# Visual studio 2010 prof. :) – Nick Peelman Apr 08 '13 at 17:12
  • 2
    You could probably do a *careful* search and replace through the designer generated code to get them all pointing to the right methods. Look for `_Click_1` and replace with `_Click`. Also, use source control! – Matt Burland Apr 08 '13 at 17:13
  • Sounds great! but... There's noting added in my designer O.O – Nick Peelman Apr 08 '13 at 17:22
  • You can try to use Windows' [Previous Versions](http://www.howtogeek.com/56891/use-windows-7s-previous-versions-to-go-back-in-time-and-save-your-files/) feature to try and recover an old file, but before you do anything else, **get source control**. – Bobson Apr 08 '13 at 17:48
  • Since I have nothing like previous Versions available I think I should just paste all the code from the previous methods to the new methods. – Nick Peelman Apr 08 '13 at 17:58
  • Previous Versions is built into Windows 7 and above. – Bobson Apr 08 '13 at 18:12
  • @NickPeelman: It has to be in there somewhere. It's not magic. WinForms writes the code that hooks up the events to their event handlers. If your form is called `MyForm.cs`, there should be a file named `MyForm.Designer.cs`. Look there. It should be in the `InitalizeComponent()` method. – Matt Burland Apr 08 '13 at 18:35

0 Answers0