[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

load a form within a form

Posted on 2004-11-08
9
Medium Priority
?
262 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:brokeMyLegBiking
9 Comments
 
LVL 10

Assisted Solution

by:heintalus
heintalus earned 1200 total points
ID: 12529109
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
 
LVL 18

Expert Comment

by:armoghan
ID: 12530164
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
 
LVL 5

Accepted Solution

by:
Ignacio Soler Garcia earned 800 total points
ID: 12531236
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Expert Comment

by:iboutchkine
ID: 12532585
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
 
LVL 4

Author Comment

by:brokeMyLegBiking
ID: 12543374
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
 
LVL 5

Assisted Solution

by:Ignacio Soler Garcia
Ignacio Soler Garcia earned 800 total points
ID: 12543725
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
 
LVL 4

Author Comment

by:brokeMyLegBiking
ID: 12543941
you are right, I love the answer. :D
0
 
LVL 5

Expert Comment

by:Ignacio Soler Garcia
ID: 12544265
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
 
LVL 4

Author Comment

by:brokeMyLegBiking
ID: 12544990
thanks again folks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Screencast - Getting to Know the Pipeline
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question