Multiple forms in a view

G

Guest

Hi,

I am trying to build an app (in VS 2005) with various "views" each
containing different "panels" similar to let's say MS Outlook or VS.

Each "panel" in these views is a form and I want to be able to use VS to
create and manage these forms individually.

The idea is that I would design and write handlers for each of these forms
independantly. I can then design the parent windows (these will be my
"views") that holds a set of the child forms (note: a child form may be
re-used in multiple parent windows).

I tried using a splitter in a form as the parent window. The splitter
creates 2 panels and what I want to be able to do is to show 2 completely
independant forms in these 2 panels.

What I did was to create 2 forms - Form1 and Form2 - each having exactly one
panel inside and a set of controls within that panel. I then created my
ViewForm with a splitter and in the c'tor of ViewForm, I did:
Form1 f1 = new Form1();
Form2 f2 = new Form2();

this.splitContainer1.Panel1.Controls.Add(f1.Controls[0]); // add the panel
in form1 to the panel 1
this.splitContainer1.Panel2.Controls.Add(f2.Controls[0]); // add the panel
in form2 to the panel 2.

Now when I show ViewForm, the controls in Form1 show up in the left pane and
the controls in Form2 show up in the right pane.

The problem however is that the event handler code for the controls is in
the individual forms (Form1 & Form2) and not in ViewForm.

I want my ViewForm to hold completely independant and self-sufficient forms
in it's "panels".

What is the best way to achieve what I want? Should I be using splitter
windows at all? Or should I be using MDI?

Note: I do not need the individual child forms to be dockable/floating. As
long as the user can resize them using a splitter I am ok.

thanks,
hari
 
B

Bob Powell [MVP]

You should probably be using MDI but manage the MDIClient's layout so as to
maintain the desired relationship of your forms.

Windows Forms Tips and Tricks has an article on painting the MDIClient
surface which shows how to obtain a reference to this intermediate control.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

This would let me create multiple floating windows within the MDI parent.
What I need is more of a splitter effect. How is that possible using MDI?

Bob Powell said:
You should probably be using MDI but manage the MDIClient's layout so as to
maintain the desired relationship of your forms.

Windows Forms Tips and Tricks has an article on painting the MDIClient
surface which shows how to obtain a reference to this intermediate control.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



Hari Menon said:
Hi,

I am trying to build an app (in VS 2005) with various "views" each
containing different "panels" similar to let's say MS Outlook or VS.

Each "panel" in these views is a form and I want to be able to use VS to
create and manage these forms individually.

The idea is that I would design and write handlers for each of these forms
independantly. I can then design the parent windows (these will be my
"views") that holds a set of the child forms (note: a child form may be
re-used in multiple parent windows).

I tried using a splitter in a form as the parent window. The splitter
creates 2 panels and what I want to be able to do is to show 2 completely
independant forms in these 2 panels.

What I did was to create 2 forms - Form1 and Form2 - each having exactly
one
panel inside and a set of controls within that panel. I then created my
ViewForm with a splitter and in the c'tor of ViewForm, I did:
Form1 f1 = new Form1();
Form2 f2 = new Form2();

this.splitContainer1.Panel1.Controls.Add(f1.Controls[0]); // add the panel
in form1 to the panel 1
this.splitContainer1.Panel2.Controls.Add(f2.Controls[0]); // add the panel
in form2 to the panel 2.

Now when I show ViewForm, the controls in Form1 show up in the left pane
and
the controls in Form2 show up in the right pane.

The problem however is that the event handler code for the controls is in
the individual forms (Form1 & Form2) and not in ViewForm.

I want my ViewForm to hold completely independant and self-sufficient
forms
in it's "panels".

What is the best way to achieve what I want? Should I be using splitter
windows at all? Or should I be using MDI?

Note: I do not need the individual child forms to be dockable/floating. As
long as the user can resize them using a splitter I am ok.

thanks,
hari
 
J

Jim Hughes

You can load a dotnet form within a container, (i.e. panel).

The key is the TopLevel property of the form, the rest of the code shown
here shows other properties you may want to adjust.

You can control the visibility and which "subform" is on top using the
BringToFront and Visible properties

You can declare events that the Parent form needs to be aware of and raise
them from within the child forms. That way the Parent Form is an observer if
and only if it wants to be :)

So in your case, create a top level form, add a panel (docked left), a
splitter, another panel (PanelImage in this case). (dock fill)

Private WithEvents _imageform As New FormImageView

Private Sub FormDocumentTree_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
_imageform.ControlBox = False
_imageform.Dock = DockStyle.Fill
_imageform.MaximizeBox = False
_imageform.MinimizeBox = False
_imageform.TopLevel = False
PanelImage.Controls.Add(_imageform)
_imageform.Show()
_imageform.BringToFront
End Sub


Hari Menon said:
This would let me create multiple floating windows within the MDI parent.
What I need is more of a splitter effect. How is that possible using MDI?

Bob Powell said:
You should probably be using MDI but manage the MDIClient's layout so as
to
maintain the desired relationship of your forms.

Windows Forms Tips and Tricks has an article on painting the MDIClient
surface which shows how to obtain a reference to this intermediate
control.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



Hari Menon said:
Hi,

I am trying to build an app (in VS 2005) with various "views" each
containing different "panels" similar to let's say MS Outlook or VS.

Each "panel" in these views is a form and I want to be able to use VS
to
create and manage these forms individually.

The idea is that I would design and write handlers for each of these
forms
independantly. I can then design the parent windows (these will be my
"views") that holds a set of the child forms (note: a child form may be
re-used in multiple parent windows).

I tried using a splitter in a form as the parent window. The splitter
creates 2 panels and what I want to be able to do is to show 2
completely
independant forms in these 2 panels.

What I did was to create 2 forms - Form1 and Form2 - each having
exactly
one
panel inside and a set of controls within that panel. I then created my
ViewForm with a splitter and in the c'tor of ViewForm, I did:
Form1 f1 = new Form1();
Form2 f2 = new Form2();

this.splitContainer1.Panel1.Controls.Add(f1.Controls[0]); // add the
panel
in form1 to the panel 1
this.splitContainer1.Panel2.Controls.Add(f2.Controls[0]); // add the
panel
in form2 to the panel 2.

Now when I show ViewForm, the controls in Form1 show up in the left
pane
and
the controls in Form2 show up in the right pane.

The problem however is that the event handler code for the controls is
in
the individual forms (Form1 & Form2) and not in ViewForm.

I want my ViewForm to hold completely independant and self-sufficient
forms
in it's "panels".

What is the best way to achieve what I want? Should I be using splitter
windows at all? Or should I be using MDI?

Note: I do not need the individual child forms to be dockable/floating.
As
long as the user can resize them using a splitter I am ok.

thanks,
hari
 

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