Embedding Forms

B

Bruce

I would like to design a number of separate forms in Visual Studio,
and then at runtime embed them into an area of another form (without
borders and title bars of course). The forms will all be placed in the
same area on the main form, and which forms are used is dependent on
navigation choices made by the user.

The container for the forms could be the main form itself, a panel on
the main form, or a tab page on the main form.

Can anyone point me in the direction of how this might be done?

--Bruce
 
H

Herfried K. Wagner [MVP]

* Bruce said:
I would like to design a number of separate forms in Visual Studio,
and then at runtime embed them into an area of another form (without
borders and title bars of course). The forms will all be placed in the
same area on the main form, and which forms are used is dependent on
navigation choices made by the user.

Usercontrols ("Project" -> "Add UserControl...").
 
C

Chris Dunaway

The container for the forms could be the main form itself, a panel on
the main form, or a tab page on the main form.

If you set the form's TopLevel property to False and its Parent property to
the container you want to put it in (Panel, form, etc), it should work
fine. When you show the form, it will appear inside the container.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
R

Roy Soltoff

Here is some code that I use to do exactly that. I have a series of modules
that implement an interface in a class file to be consistent. The modules
show a form which may show other modal dialogs. The external app
instantiates the module, then uses the following interface method to 'open'
it. If you are going to have the 'module' raise events, you have to do this
by using an interface. The DotNet documentation has a 2-pager that covers
the interface part. See "Walkthrough: Creating and implementing Interfaces".
I also provide methods in the interface to handle a resize of the app to be
able to call the module to resize itself. Likewise, a 'close' method is
useful also shown below.

Public Function OpenModule(ByVal oParent As Object, ByRef oChild As Object)
As Boolean Implements ModInterface.IModule.IGUIModule.OpenModule

Try

frmModule.Parent = oParent ' Form parent

frmModule.gobjClassParent = Me ' Form's class parent

frmModule.Show()

mbolClientOpen = True

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Critical)

End Try

End Function

Public Sub ResizeModule(ByVal X As Integer, ByVal Y As Integer, ByVal Width
As Integer, ByVal Height As Integer) Implements
ModInterface.IModule.IGUIModule.ResizeModule

Try

frmModule.SetBounds(X, Y, Width, Height)

Catch ex As Exception

PostError(MODNAME, "ResizeModule", ex)

End Try

End Sub

Public Sub CloseModule() Implements
ModInterface.IModule.IGUIModule.CloseModule

Try

frmModule.Visible = False

frmModule.Parent = Nothing

Catch ex As Exception

PostError(MODNAME, "CloseModule", ex)

End Try

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top