VB2010 - MDI Settings, child form not bound

bede123
bede123 used Ask the Experts™
on
hi all,

please can you have a look at my code.

basically when i click the button on form1 i want form2 to open but to be bound within form1 which is set as mdi = true

but when i click on the button form2 opens but it is free to travel outside of the form1, i.e. it does not apear to be bound by form1

any ideas?

 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Form2.MdiParent = Me

    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Form2.MdiParent = Me.MdiParent
        Form2.Show()
    End Sub


End Class

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Change line #8 so you have "Me" instead of "Me.MdiParent":
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Form2.MdiParent = Me
        Form2.Show()
    End Sub

Open in new window

Author

Commented:
yep you got. thanks very much.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
*This fixed it because when you had "Me.MdiParent", you were assigning NOTHING as the MdiParent of Form2, since Form1 does not have an MdiParent.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial