Reputation: 232
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:
And here's application:
How to fix this to show Form2 correctly?
Upvotes: 1
Views: 1318
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.
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