Search code examples
c#winformswindowmdichildmdiparent

Maximize MDIchild to MDIParent automatically on form load


I am new to WinForms and working on a parent child application. I have created a MDI parent and loading a child form inside it.

Once I select the menu in MDI parent, the child form gets loaded but not fully maximized. I have to manually maximize it to fit the MDI Parent. Below is the screenshot of what I am getting during form load.

Actual result

Every time on form load i have to maximize it. Below is the code that I am using.

private void newDeploymentToolStripMenuItem_Click(object sender, EventArgs e)
    {
        NewDeployment nwDeploy = new NewDeployment();
        nwDeploy.MdiParent = this;
        nwDeploy.Dock = DockStyle.Fill;
        nwDeploy.WindowState = FormWindowState.Maximized;
        nwDeploy.Show();
    }

I want the child form to be loaded in maximised state as shown below. I have searched google but I am getting the same code that I have used.

Is there any other way of doing this? Any help will be highly appreciated.

Expected


Solution

  • Thanks to Jimi and Sinatr, I have modified the code by loading the form then modify its window state to maximized.

    Below is my updated code

     NewDeployment nwDeploy = new NewDeployment();
                nwDeploy.MdiParent = this;
                nwDeploy.Dock = DockStyle.Fill;
                nwDeploy.Show();
                nwDeploy.WindowState = FormWindowState.Maximized;