views:

62

answers:

3

I had a working program (Windows Forms Project) complete with buttons, labels, textboxes e.t.c. and the underlying code.

In an attempt to shortcut my work, I decided to add tab controls and move everything in my main form into tab 1 (cut and pasted). As you can imagine it didn't work. I then got rid of the tab conrol and pasted everything back into the main form but the program doesn't work anymore. Can someone tell me what's wrong please?

I'm working in MS V studio 2008 express Thanks.

+4  A: 

I have done this many times, but I usually just drag them into the TabControl. Maybe in the cut and paste operation your controls have become unwired from the event declarations.

Brad
A: 

Possibly some of the events had code lost. If you do it again it will probably work. For an alternative method see my message

sgmoore
+1  A: 

The event handlers that you coded are still there. However, they are not associated with the control any more. I'm not sure if you're using VB.Net or C#, but the fix is the same - it's manual and tedious if you have a bunch of controls, but not too difficult. Here are the instructions for fixing a single button control, and you'll have to apply the concepts across the board.

These instructions are specific to C#. I can give you VB instructions as well as I've done this plenty of times.

Double click on the button to generate a new event handler. If the button is named Button1, the original event handler was probably called Button1_Click. Now it should be Button1_Click1.

Delete the Button1_Click1 function and compile. You'll get errors and if you doible-click on the error in the error pane it will take you to the form,designer.cs file to a line that looks like:

this.Button1.Click += new System.EventHandler(this.Button1_Click1);

Change this to

this.Button1.Click += new System.EventHandler(this.Button1_Click);

to point to the previously existing event handler, and the event handler will be fixed.

David Stratton
PS, as @Brad posted, dragging instead of cutting and pasting does avoid this situation.
David Stratton
Thank you oh so much, I was working in C# MS Visual Studio 2008 express, I found out that by checking the events list window pane I could select each control and re-pair it with the right function.
Dark Star1