Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to move components from Form to Tab Pages

Status
Not open for further replies.

philrock

Programmer
Jan 29, 2004
109
US
I'm a vb noob using vb 2008 Express. I'm writing a moderately complex program for doing engineering calculations. I've made a GUI on one Form with several dozen text boxes, combo boxes, and labels. A lot of work has gone into both the code and the physical placement and alignment of the components.

In true noob fashion, I did not realize until now that I should have split up the GUI onto several Tab Pages instead of trying to do it all on just one Form. Is there a way that's not too painful to move what I've done from the Form onto Tab Pages? I've tried simple cut & paste, but this did not work. In any case, I realize I will have to do a lot of "find and replace" to correct references to the components.
 
Actually, "cut & paste"ing will do just fine, but you'll have to set each control's event handlers.

For example:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) [blue]Handles Button1.Click[/blue]
    'your codes
End Sub

will loose the blue phrase when you cut & paste the Button1 control. Write the blue phrase back, then you're done.

Or, you can do "drag & drop". I think that this is a simpler way because this will not remove the blue phrases.

Good luck.
 
As mansii mentioned, "drag & drop" will work just fine. The only thing to that I'd add is to Ctrl-click the controls you want to move so they're all selected together and keep their positions relative to each other.
 
Drag and drop worked like a charm. I did not even have to edit the code at all - which I actually don't understand.

I put the TabControl on the same form that all the existing controls are on. Then I moved about 80% of the existing controls to TabPage1. Clicked "Run", tried the program, and it worked just as it did before the TabControl was there.

I would have thought that all the controls that I moved would now have a new parent - the TabControl or the TabPage, and that would necessitate editing the references to the controls. Am I wrong on that? Or does that not matter? Did vb do some automatic editing in code modules that I normally do not look at?
 
Yes. If you were to look at the forms designer code you would have seen that it goes from adding the control directly to the form's controls and instead adds it to the tabpage's controls. The parent is simply determined by which control collection the control is added to. The IDE handles all of that as a matter of course when you drop/paste it.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top