user3613916
user3613916

Reputation: 232

MDI child with FormBorderStyle = None not maximizing correctly

I am writing an application using Windows Forms. I need to use MDI child with FormBorderStyle set to None. Problem is, when I maximize, child doesn't show up correctly. Code to show Form2 is:

  this.WindowState = FormWindowState.Maximized;
  Form2 frm = new Form2();
  frm.MdiParent = this;
  frm.Size = this.ClientSize;
  frm.ShowInTaskbar = false;
  frm.WindowState = FormWindowState.Maximized;
  frm.Show();

Here's how Form2 looks in designer:

enter image description here

And here's application:

enter image description here

How to fix this to show Form2 correctly?

Upvotes: 1

Views: 1318

Answers (1)

Jarrett Robertson
Jarrett Robertson

Reputation: 459

You can try the following code. It appears to do what you are looking for.

        this.WindowState = FormWindowState.Maximized;
        Form2 frm = new Form2();
        frm.MdiParent = this;
        frm.Dock = DockStyle.Fill;
        //frm.Size = this.ClientSize;
        frm.ShowInTaskbar = false;
        //frm.WindowState = FormWindowState.Maximized;

        frm.Show();

The only change was added frm.Dock = DockStyle.Fill; and commented out setting the size and window state of Form2.

When I run the program this is the effect.

enter image description here

I do agree this seems to be the wrong way to get this effect and a user control would be better most likely.

Upvotes: 1

Related Questions