Dynamically creating and displaying forms in a split container

I have created a Windows application using VS 2005 C#. I added a spilt container in the client area of the main form. I added controls to the left panel1 of the split container control. These controls work fine. I want to display other forms that I have created in the project in the right panel2 of the split container at runtime. I want to be able to create and display a form in the right panel of the split container based on events in the main form. i.e. menu, tree control, etc.

I have tried SDI and MDI and I can not make either work. Does anyone have any suggestions or sample code on how I can make this work? Should the forms be user controls instead? Thanks for the help.

[685 byte] By [DonHames] at [2007-12-16]
# 1
Yes, you cannot host a Form within another Form as a control. So make different User Controls which are composed on various other controls (all known as composite user controls). And load these user controls in the rightpane as required.

Regards,
Saurabh Nandu
www.MasterCSharp.com
www.AksTech.com

SaurabhNandu-MVP at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
Thanks Saurabh for the reply. I was wondering if using panels to host controls could work as well as the user controls you suggested. Then, you can hide/show each panel based on the menu items you select. If yes, what is the better choice between the two? Any advice on that?

Thanks, Pano

pano at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 3
Thanks Saurabh for the reply. I created user controls instead of forms now. They user controls appeared in the toolbox and I can drag them to the right panel2 of the split container. I built and ran and it appears fine.

Now I am trying to create the user control at run time by responding to an event. I copied the code that was generated from when I dragged it to the panel2 and added a .Show() to the user control.

When I build and run, click and cause the event to fire, the user control does not appear. I ran in debug to make sure the code was being executed and it is. The user control does not appear. What am I missing? Any ideas? Thanks.

DonHames at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 4
pano wrote:
Thanks Saurabh for the reply. I was wondering if using panels to host controls could work as well as the user controls you suggested. Then, you can hide/show each panel based on the menu items you select. If yes, what is the better choice between the two? Any advice on that?

Thanks, Pano

Panels would work. The general guidline would be that if you wish to reuse the controls somewhere else then its good to build a User Control out of it which promotes reusablity. If its just for a specific form then you can just place the relevant controls in a Panel and use them - that would work fine.
Regards,
Saurabh Nandu
www.MasterCSharp.com
www.AksTech.com

SaurabhNandu-MVP at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 5
Could you post the relevant code?
BonnieB at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...