load a form within a form

Is there a way to load a form within a form. Say forexample, load a form within a panel?

I would like to be able to keep by code in separate forms, but I dont want to show the navigation controls for each form when I embed it in my main form.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Yes its quite easy

to load it within a form you could use

frmUser = New UserForm
frmUser.TopLevel = False
frmUser.Dock = DockStyle.Fill

to load it into a panel you could use
frmUser = New UserForm
frmUser.TopLevel = False
frmUser.Dock = DockStyle.Fill

Another way is to make a Inherited Form, the parent form will contain the general functionality and the child form can have child functionality, but the controls of both the forms will be visible
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
I think that what you want is what I use to do.

Just program a user control with all the functionality that you want, and the show/create - hide/destroy it as you need. For example, if I do a form with a tab control I do a user control for all the components that go inside each tab. This way I have one file for each tab and the program is more clear. So the structure is like this (for example):

Main Form.vb: 3 user controls.

User control 1.vb: all the stuff you want goes here (buttons, labels, etc)
User control 2.vb: all the stuff you want goes here (buttons, labels, etc)
User control 3.vb: all the stuff you want goes here (buttons, labels, etc)

Askme more if you want.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f As New Form2()
        f.TopLevel = False
'f is in coordinates of form1
        f.Left = 0
        f.Top = 0
    End Sub
brokeMyLegBikingAuthor Commented:
heintalus , SoMoS,

Your answers are BRILLIANT,BRILLIANT,BRILLIANT,BRILLIANT,BRILLIANT,BRILLIANT,BRILLIANT,BRILLIANT,BRILLIANT!!!!! This is great, your two solutions very much solves my problem. I have lost a lot of sleep over this! Now I can have my cake and eat it too! And the best part, they are very easy.

Question: What is the easiest way to convert a form to a userControl? Why do you need to set "topLevel" to false?


Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
You will love the anwser:

Just change the "Inherits System.Windows.Forms.Form" at the class declaration to  "Inherits System.Windows.Forms.UserControl".

That's all folks!

brokeMyLegBikingAuthor Commented:
you are right, I love the answer. :D
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Ops, I forgott one question:

'A TopLevel form is the one that hasn't a main form or the one that has as main form the desktop. The toplevel forms are used as the main form of the application. So to use it, the property has to be set to false because the form has a main form (f1).


P.D: Come'on with the points brother!
brokeMyLegBikingAuthor Commented:
thanks again folks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.