none
Maximize child MDI form RRS feed

  • Question

  • Hello,

    How do I maximize a child MDI window? I set the WindowState in the forms designer, but it doesn't seem to be working. I tried it programatically too, but in vain.

    Thanks

    • Moved by CoolDadTx Wednesday, November 2, 2011 2:38 PM Winforms related (From:Visual C# IDE)
    Wednesday, November 2, 2011 10:38 AM

Answers

  • Hi sinu,

    Add this code to your child form load event:

    private void Form2_Load(object sender, EventArgs e)
            {
                this.WindowState = FormWindowState.Maximized;
            }
    

    Hope it helps.

    • Marked as answer by sinu Thursday, November 3, 2011 5:40 AM
    Thursday, November 3, 2011 1:08 AM
  • Or if in case if the code above would not still work for your application, maybe you could try this sample code which is working on my side.

    Assuming that you have added a menu strip from your parent form:

    At mdi Parent Form1:

    public Form1()
            {
                InitializeComponent();
                this.IsMdiContainer = true; // set this form1 as mdi parent
                this.WindowState = FormWindowState.Maximized; // set the mdi parent to maximize
            }
            Form2 form2;
            private void childForm1ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                //handle this code to avoid opening of multiple forms
                foreach (Form childForm in this.MdiChildren)
                {
                    if (childForm.GetType() == typeof(Form2))
                    {
                        childForm.Focus();
                        return;
                    }
                }
                form2 = new Form2(); 
                form2.MdiParent = this;
                form2.Show(); //open child form2
            }
    

    then at mdi child form2:

    private void Form2_Load(object sender, EventArgs e)
            {
                this.WindowState = FormWindowState.Maximized;
            }
    
    Hope it helps.

    • Marked as answer by sinu Thursday, November 3, 2011 5:40 AM
    Thursday, November 3, 2011 1:22 AM

All replies

  • Hi sinu,

    Add this code to your child form load event:

    private void Form2_Load(object sender, EventArgs e)
            {
                this.WindowState = FormWindowState.Maximized;
            }
    

    Hope it helps.

    • Marked as answer by sinu Thursday, November 3, 2011 5:40 AM
    Thursday, November 3, 2011 1:08 AM
  • Or if in case if the code above would not still work for your application, maybe you could try this sample code which is working on my side.

    Assuming that you have added a menu strip from your parent form:

    At mdi Parent Form1:

    public Form1()
            {
                InitializeComponent();
                this.IsMdiContainer = true; // set this form1 as mdi parent
                this.WindowState = FormWindowState.Maximized; // set the mdi parent to maximize
            }
            Form2 form2;
            private void childForm1ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                //handle this code to avoid opening of multiple forms
                foreach (Form childForm in this.MdiChildren)
                {
                    if (childForm.GetType() == typeof(Form2))
                    {
                        childForm.Focus();
                        return;
                    }
                }
                form2 = new Form2(); 
                form2.MdiParent = this;
                form2.Show(); //open child form2
            }
    

    then at mdi child form2:

    private void Form2_Load(object sender, EventArgs e)
            {
                this.WindowState = FormWindowState.Maximized;
            }
    
    Hope it helps.

    • Marked as answer by sinu Thursday, November 3, 2011 5:40 AM
    Thursday, November 3, 2011 1:22 AM
  • This property changing action would need to put after the MDI Child Form is instant(in the MDI Child Form.Load event handler method, or set this property after you instant it in the MDI parent Form as Hardz written).

    Have a nice day!


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, November 3, 2011 3:58 AM
    Moderator