New to VB.Net programming. I want to open Form2 from a button on Form1. Got this far.
Form2 has no border, I want it to appear to be part of Form1, (like a frame in a web page, everything else on the page stays the same except for this Form2 overlay). I need to position Form2 before showing (I think I can do that part) but then if user moves form1 or resizes it, Form2 is now left hanging in the wrong place.
Another way to look at this is the idea of Access forms and subforms. Here we embedded one form into another, and the subform always stayed attached.
What is the best way to do this in VB Any help and guidance is appreciated...

Docking one form to another
SQL McOLAP
frm.BringToFront()
and that should take care of it. If not, let me know and I'll check it out.
gatalec
Now one further question. When I "close" Form2 in this manner, I want Form2 to check for changed records, etc. and warn the user to update data before closing. I tried to put a msgbox message in the form2.closing eventhandler but it appears to not be called. Is this because it is now a control
How would I do this
Mathijs van Bockhooven
<a href="http://www.erikporter.com/images/s1.png">We</a> <a href="http://www.erikporter.com/images/s2.png">actually</a> <a href="http://www.erikporter.com/images/s3.png">used</a> <a href="http://www.erikporter.com/images/s4.png">it</a> <a href="http://www.erikporter.com/images/s5.png">for</a> <a href="http://www.erikporter.com/images/s6.png">this</a>
the center of each one of those screens is a form setup like i think you're looking for. Basically the Forms Collection above will help you do what Ken and Jacob have been describing.
wrvjohn
Private frm As Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm = New Form2
frm.Location = Panel1.Location
frm.TopLevel = False
frm.Size = Panel1.Size
Me.Controls.Add(frm)
frm.Show()
End Sub
That should do the trick. If not, it should only require minimal tweaking.
P3T3R 7
Dim i As Integer = 0
Dim blnFound As Boolean = False
Do Until blnFound Or i = Me.Controls.Count
If TypeOf Me.Controls(i) Is Form2 Then
blnFound = True
Else
i += 1
End If
Loop
If blnFound Then
Me.Controls.RemoveAt(i)
End If
Silk Brick
Private frm As Form2
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
frm = New Form2
frm.Location = PointToScreen(Panel1.Location)
frm.Size = Panel1.Size
frm.Owner = Me
frm.Show()
End Sub
Private Sub Form1_Move( _
ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Move
If Not frm Is Nothing Then
frm.Location = PointToScreen(Panel1.Location)
End If
End Sub
This just opens the new form when you click the button, and moving the main form causes the child form to move with it. Again, this is the "brute force" solution, and I'd love to see one that works better.
stalamoni
ger001
Jazz1234
Mhorn821
This worked great! I also added the frm.dock = dockstyle.Fill to keep the size correct.
Now another question:
How do I reference this "control" so as to "close" it when I want to open a different form instead I have tried to figure out the control collection and while I have figured out that the name of this form control is the same name as the form class from which it is created, I can't seem to get the main form (form 1) to identify and remove it. I am sure it's something simple, but help me.....
jadoger
renegade800X
The other code option did not show the form at all. Nothing appeared, even though I got no errors.
Any more help guys
Ranjith_Msdn
Muhammad Ismael