Its called an MDI container. Parent containers and child forms. See below:
Unless otherwise noted, all this will go into the respective form's load event.
Go to form1 and in the properties list to the right set IsMdiContainer = True.
Since Form1 is your main form, each subsequent form will be named like I have shown here. (note: you can name whatever you want.)
Place this in Form1_Load (Handles myBase.Load) <- that event
Code:
form2.MdiParent = Me
form3.MdiParent = Me
form4.MdiParent = Me 'this tells all other forms that the MDI parent container is ME (form1)
Make sure you assign Form1 as the parent for EACH new form you make or it wont register correctly.
ALTERNATIVELY, in each "child" form's load event you can put:
Code:
MdiParent = Form1 '(or whatever your MDI parent is named)
I just think its easier to keep all the code centralized and put it in the Form1_Load event like I said above.
Lastly, to show the forms when you want them to, do NOT use:
That will make it the topmost and wont let you click to other forms within the container until it is closed. Instead, use:
To close each form you can use:
Which will just hide the form and remember its location that you dragged it to within the MDI container (best option). Alternatively you can always use:
***************************
Those are the basics. To get more advanced you can make 2 forms appear at once at the click of a button and arrange them side by side regardless of where they appear. Also, I think this will solve your forms appearing over other forms.
To make a new form appear next to the previous one do this:
In the button click event for whatever button is supposed to make the new form appear put: (lets assume the first form is FormA and that the new one you want to appear beside it is FormB)
Then in the new form's (FormB) load event, put this:
Code:
Me.Location = New Point(FormA.Location.X + FormA.Width, FormA.Location.Y)
"Point" is represented in (X, Y) coordinates from the top left of the form. If you want the form to appear 50x50 pixels into the MDI container you would type:
Code:
Me.Location = New Point(50, 50)
LocationX and Y get the locations of the top left of the form, to make it snap to the formA's right side you would add the width to the X to move it over that many pixels.
Inversely, if you wanted it to appear to the left you would need to reverse which form's dimensions you reference. For the left instead, use:
Code:
Me.Location = New Point(FormA.Location.X - Me.Width, FormA.Location.Y)
This will put it "formB's width" to the left (X axis) of formA.
To keep it locked there as you move either form around would require either loops to update the X,Y locations or a timer event to update (set to 10ms or less for smoothness)
Really hope that helped you.