The case of the disappearing code.

  • Thread starter Thread starter RD Holland
  • Start date Start date
R

RD Holland

Guest
I've been working in a VS C# form project. I have double-clicked buttons and the IDE inserts an event handler. I have written lots of code in the handlers. Today I decided to move the controls around. I moved one button from the bottom of the form to the top. I did a build and ran. When I resized, I realized I had not changed the layout for two of the buttons I moved, one of which I moved to the top of the form. So I stopped the run and went back to form designer and changed the layout so the buttons moved as I needed them to when resizing. Ran again. Resized to verify the UI moved correctly as I resized the form.

So far, so good.

Then I did some testing. When I clicked the button I moved from the bottom to the top, nothing happened. I had done no code changes to the button even handler. So in the code view, I went to the button handler and ... all my code was gone! I hit control-z and got some message telling me I had form changes and might want to go to the design view and hit undo from there. I declined since I wanted to get my code back in the code view. But, the code would not reappear. So I went to the form design view and hit undo. Nothing.

What the heck did the IDE do deleting all that code? The name of the button didn't change. And even if I changed the name I would not expect the IDE to auto delete any code in my code view.

I'm really disappointed that working in the form design view would cause code to just vanish from the form.cs file. This is a new project so I haven't checked it into TFS. Of course, that would only provide a "backup" if I had constantly checked in every little code change.

I now have to embark on refactoring - redesigning the code to protect me from the IDE (form designer) by creating a separate method for every event handler and having the event handler do nothing but invoke the method. What a PITA.

Seems like a major but to me. I lost hundreds of lines of code!


R.D. Holland

Continue reading...
 
Back
Top