Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to code up a program that has a parent window/form that would have a region of it that will be a "selectable" child form from menu items.

The path I currently am on is trying to "nest" a child form in a panel control on the parent window. However, I'm having trouble trying to get the child form to initialize in the panel control. I'm not sure how to do this. I currently can have the child form display when the menu item is selected, but it is not constrained or fixed to the parent window.

Is this a correct approach? Is there a better alternative?

Form 1:

C#
public partial class sfsResgenForm : Form
    {
        public sfsResgenForm()
        {
            InitializeComponent();


        }

        // Menu Item Controls

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)  // Exit Menu Item
        {
            if (MessageBox.Show("Close and Exit?", "Confirm Exit", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                // a 'DialogResult.Yes' value was returned from the MessageBox proceed with your action

                this.Dispose();
            }


        }

        private void newCharacterToolStripMenuItem_Click(object sender, EventArgs e)    // Go to Character Generator
        {
            chargenForm1 newMDIChild = new chargenForm1();
            // Set the Parent Form of the Child window.
            // newMDIChild.MdiParent = this;
            // Display the new form.
            newMDIChild.Show();



Form 2:

C#
public partial class chargenForm1 : Form
    {
        public chargenForm1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Dispose();

        }
    }


Thanks in advance.

Sig Pimp
Posted
Updated 10-Jul-11 11:55am
v2

Try playing around with WPF - it has better support for nesting windows inside windows, nested inside windows - and so on ...

There are also nice libraries like AvalonDock[^] that will help you manage the UI. SAKryukov do have a point - to much of this may easily confuse users ...

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Jul-11 18:36pm    
Reasonable advice, my 5, but this is not where WPF really has distinct benefits. If Form nesting panels present no problems at all. Everything with is no MDI can be done quite well.
--SA
Espen Harlinn 10-Jul-11 18:51pm    
Think of an UML class diagram application - you can use windows for each entity or interface, and style them so they doesn't look like "Windows" anymore, but still retain their moveable behaviour, and ability to contain a content control. That's fairly useful ... it's not MDI as such, just windows nested inside windows ...
Sergey Alexandrovich Kryukov 11-Jul-11 0:54am    
Yes, I understand, thanks for this note.
--SA
thatraja 10-Jul-11 23:02pm    
I love open-source, 5!
Listen to a good friendly advice: don't torture yourself and disgust your users — never use MDI. It is highly discouraged even by Microsoft and virtually never used in any really working projects.

See also:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

Instead, do something simple and really robust and convenient. Simplest thing: make a tabbed UI in one form based on TabControl.

—SA
 
Share this answer
 
Comments
Espen Harlinn 10-Jul-11 18:13pm    
Nice set of links, my 5
Sergey Alexandrovich Kryukov 10-Jul-11 18:37pm    
Thank you, Espen.
--SA
thatraja 10-Jul-11 23:01pm    
Good links, 5!
Sergey Alexandrovich Kryukov 10-Jul-11 23:33pm    
Thank you, Raja.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900