Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I create an MDI child window?

Here is a simple, complete source for creating MDI child windows. To build, reference System, System.Drawing, and System.Windows.Forms.

using System;
using System.Windows.Forms;

namespace Application1
{
    class Program
    {
        static void Main( string[] args )
        {
            Application.Run( new MDIParentForm() );
        }
    }

    class MDIParentForm : Form
    {
        public MDIParentForm()
        {
            IsMdiContainer = true;
            MenuStrip mainMenuStrip = new MenuStrip();
            Controls.Add( mainMenuStrip );
            MainMenuStrip = mainMenuStrip;
            ToolStripItem addMDIChildMenuItem = 
              mainMenuStrip.Items.Add( "Add MDIChild" );
            addMDIChildMenuItem.Click +=
              new EventHandler( addMDIChildMenuItem_Click );
        }

        void addMDIChildMenuItem_Click( object sender, EventArgs e )
        {
            Form f = new Form();
            f.MdiParent = this;
            f.Show();
        }
    }
}