1

How can I show a child form within a mdi container form which its windowstate= maximized ?

when I put these below lines of code when my child form is loading (by clicking on a menu Item of my Main form), the child form loses its parent position and does not show within its parent form.

private void mnuUnit_Click(object sender, EventArgs e)
{
    frmUnit frm = new frmUnit();
    frm.MdiParent = this;
    frm.WindowState = FormWindowState.Maximized;
    frm.Show();
}
Himanshu
  • 31,810
  • 31
  • 111
  • 133
odiseh
  • 25,407
  • 33
  • 108
  • 151

2 Answers2

9

Did you forget to paste your code?

To show an MDI child form as maximized, you do the following:

// This is a method on the MDI parent (IsMdiContainer = true)
private void Button1_Click(object sender, EventArgs e)
{
    var myForm = new MyCustomForm();
    myForm.MdiParent = this;
    myForm.WindowState = FormWindowState.Maximized;
    myForm.Show();
}
Codesleuth
  • 10,321
  • 8
  • 51
  • 71
0

You can set the dock style to fill and before calling show, use

myForm.BringToFront();
Himanshu
  • 31,810
  • 31
  • 111
  • 133
nipiv
  • 332
  • 1
  • 5
  • 18