Tuesday, February 12, 2008

How to make a form a child of a control in VB.NET

I had a control.  The control would open a Form.  I wanted to make the Form a child of the control.  For some reason I couldn't get this to work.  What I wanted was this Form to be on top of the control, and I didn't want the form to be moved out of the control.  I also wanted the form to close if the control was closed.  Anyways, I just couldn't get it to work properly.

I tried doing the following:
                Form1.Owner = Me.Parent         

But then I had to set the Form1 as the TopMost control.  And this didn't allow me to click on other parts of the control.

Anyways, the things that worked was thie following line:
                Form1.TopLevel = False                'This is the key line in order to make Form1 a Child of this Control

I also do the following (which I did before):
                Form1.Parent = Me
                Form1.IsMdiContainer = False
                Form1.BringToFront()

I no longer do the call to Form1.Owner = Me.Parent as it is not needed and having that call there messes things up.



No comments: