Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving Controls from One Tab Page to Another

I currently am working on a WinForm project in which there are several different tabs. Within each tab there are various controls such as buttons, sub-tabs, text-boxes, ect...

I need to consolidate the overall application which involves taking certain controls from one tab and moving them to another. When I first tried doing so, I simply copy and pasted the controls. As you can imagine this didn't work due to the fact that I didn't move the properties with the controls, I really just created NEW ones on a different tab. Therefore when I complied the code, nothing worked because there was no code assigned to the new controls.

When I tried it again, this time I CUT and paste which also maintains the same properties as the old controls (specifically the reference name in the code), so as far as I can tell, the code should identify the controls by name, and apply the same actions. However, when I compile the code, the application successfully builds but the controls do not perform any actions.

At this point I am not sure what to do...

like image 728
DeeWBee Avatar asked Jun 19 '14 15:06

DeeWBee


3 Answers

Use the Document Outline.

View... Other Windows... Document Outline.

Select the required component and drag it from one tab page to the other in the tree control. I did this and the actions are preserved in the new tab page.

like image 59
Paul Richards Avatar answered Nov 15 '22 08:11

Paul Richards


Drag the item out of the tab control and onto the form itself. Change to the other tab. Then drag the item into that tab. It is essentially 2 drag moves, but since you do not ever cut, all code linking is maintained. If your tab control takes up the entire form, simply make it smaller while you do the preceding steps and then make it large again when you are done.

like image 42
Webmasterjeff Avatar answered Nov 15 '22 08:11

Webmasterjeff


When you "cut" the controls, you sever the connections between the controls and their respective events. When you "paste" them again, they're not hooked up to the events anymore, so they don't appear to do anything.

The "event" methods should still be present in your code, but you'll have to manually go through and subscribe each event to each control again (via the Properties window).

Alternatively, revert those changes, then open the .Designer.cs file and look for something like this:

this.tabPage1.Controls.Add(this.dataGridView1);

Which (for example) places dataGridView1 inside tabPage1.

If you wanted to move the DataGridView to another TabPage, you could just change this.tabPage1 in the above code to this.tabPage2.

this.tabPage2.Controls.Add(this.dataGridView1);

Then you can flip back over to the designer view and move the control around to wherever you want it within the TabPage.

like image 2
Grant Winney Avatar answered Nov 15 '22 07:11

Grant Winney