Reputation: 1
I have 2 Forms; Form1 and Form2. In Form1, there's a MenuStrip and a button. When I click the button, Form2 appears below the Form1 button.
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.MdiParent = this;
frm.StartPosition = FormStartPosition.CenterScreen;
frm.WindowState = FormWindowState.Maximized;
frm.Show();
}
Upvotes: 0
Views: 1199
Reputation: 314
When you set IsMdiContainer
to true
. The form automatically adds System.Windows.Forms.MdiClient into ParentForm.Controls
. It usually adds after all docked controls are added. So that, It appears below the button. You can undock this MDI container. You can customize it. It's only possible in the code. Like:-
foreach (Control control in Controls)
{
if (control is MdiClient mdic)
{
mdic.Dock = DockStyle.None;
mdic.Bounds = new(50, 50, 200, 200);
//You can use Size & Location instead.
}
}
In this way, you can't change the background of the parent form. But you can do if you add this MDI container manually. Then, you can't set Form.MdiParent
to ParentForm
. You've to write it manually. Like:-
MdiClient mdic = new MdiClient();
ParentForm.Controls.Add(mdic);
//Customize your MdiClient in this line
mdiClient.Controls.Add(ChildForm);
Upvotes: 0
Reputation: 66501
Child forms in an MDI container always underlay other controls that are directly placed on the MDI container:
You'll see the same behavior if you move the Form underneath your menu too, although since the MenuStrip is docked, you should see scroll bars that allow you to view the entire Form.
Either merge your button onto the MenuStrip:
Or dock it to an edge somewhere: (this looks ridiculous, but it's just to demonstrate; you could dock a panel and move it in there, or play around with a ToolStrip, for example)
Upvotes: 3