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.


Joseph
LVL 4
brokeMyLegBikingAsked:
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.

heintalusCommented:
Yes its quite easy

to load it within a form you could use

frmUser = New UserForm
frmUser.TopLevel = False
frmUser.Dock = DockStyle.Fill
Me.Controls.Add(frmUser)
frmUser.Show()

to load it into a panel you could use
frmUser = New UserForm
frmUser.TopLevel = False
frmUser.Dock = DockStyle.Fill
Me.pnlDetail.Controls.Add(frmUser)
frmUser.Show()

HTH
Andy
0
armoghanCommented:
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
0
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.

SoMoS
0

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.

iboutchkineCommented:
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
        Me.Controls.Add(f)
'f is in coordinates of form1
        f.Left = 0
        f.Top = 0
        f.Show()
        f.BringToFront()
    End Sub
0
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?

-brokeMyLegBiking



0
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!

SoMoS
0
brokeMyLegBikingAuthor Commented:
you are right, I love the answer. :D
0
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).

SoMoS

P.D: Come'on with the points brother!
0
brokeMyLegBikingAuthor Commented:
thanks again folks!
0
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.