Karthik Venkatraman
Karthik Venkatraman

Reputation: 1657

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

Upvotes: 1

Views: 1366

Answers (2)

RiverNet
RiverNet

Reputation: 121

The best way to do this is to set the child form's WindowState to Maximized from within its own Load event. Works every time.

Upvotes: 0

Karthik Venkatraman
Karthik Venkatraman

Reputation: 1657

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;

Upvotes: 1

Related Questions