StrataFrame Forum

How to place a form inside a panel

http://forum.strataframe.net/Topic27700.aspx

By Ger Cannoll - 7/20/2010

I have a main form which has a menu on it and menu items call various forms. When the called form displays, it can display on top of the menu. How do I avoid this. Probaly a panel is the solution as a placeholder but am not sure how to place the called from into the panel. Also, does this have any implication for MDI forms .
By Edhy Rijo - 7/20/2010

Hi Gerard,



I believe your main form need to be an MDI and then each form will be a child of the MDI form.



Trent has posted some sample on how to create your own MDI form here, just look in the forum for "MDI". Also the StrataFlix sample have some code on how to create your own MDI form and how to call your other forms and make them child of the MDI parent.
By Greg McGuffey - 7/20/2010

You'll have to experiment with this, but you should be able to do this via code. I.e. something like this:



//-- Instantiate form, set it to be NOT top level.

MyChildForm frm = new MyChildForm();

frm.TopLevel = false;



//-- Add this to the form's collection of controls.

this.Controls.Add(frm);



//-- You still have to call show...

frm.Show();




A couple of things to note:

- You have to set the TopLevel property to false, otherwise you'll get a "Top-level control can't be added to a control" exception.

- You must also show the added form, or you won't see anything.

- You can add it to other containers. E.g. a panel, a splitter control's panel, etc.

- The form will be movable and sizable if configured.


By Greg McGuffey - 7/20/2010

As Edhy stated, an MDI setup is also valid. Not sure which is what you want, but now you have options. BigGrin
By Ger Cannoll - 7/20/2010

Hi. Thanks for all your replies. I am having difficulty 'adding' my form to the panel. I thought  I could do something like:

this.themedPanel1.Add(mycalledForm);

but there is not an Add method for themedPanel1 that I can see at least.  Is there another way of doing this

By Ger Cannoll - 7/20/2010

ok. Did a bot of digging around and can now add the form to a panel:

themedPanel1.Controls.Add(smaForm);

By Greg McGuffey - 7/21/2010

Yep, that's the it! Glad your getting it going!