Reputation: 993
When I click on a button in the main form, I want another form to open within the main form. This works so far with the following code:
private void btnOpenChildForm(object sender, EventArgs e)
{
ChildForm Form = new ChildForm();
this.IsMdiContainer = true;
Form.MdiParent = this;
Form.Show();
}
Problem:
The buttons and other controls of the main form are still visible in the child form. I tried it with Form.BringToFront()
, but it did not work neither.
Update
This is what worked so far for me, after deciding to change the GUI design. I took a ToolStripMenuItem instead of the buttons I had before.
A global variable(I think I have to improve that)
ChildForm frmChildForm;
The click method:
private void frmChildFormToolStripMenuItem_Click(object sender, EventArgs e)
{
if (frmChildForm == null || frmChildForm .IsDisposed == true)
{
frmChildForm = new ChildForm();
}
this.IsMdiContainer = true;
frmChildForm.MdiParent = this;
frmChildForm.WindowState = FormWindowState.Maximized;
frmChildForm.Show();
}
Upvotes: 2
Views: 3911
Reputation: 463
Like i said Ideally the MDI should only have the Menu control and Status Bar and that would be the intention of a MDI. To just act as a container for other forms nothing else.
So if you just want a child form to open up on top of your parentform do this (SDI way).
private void btnOpenChildForm(object sender, EventArgs e)
{
//if you just want the form to show on top do not make the MDI
ChildForm Form = new ChildForm();
Form.Show();
Form.Owner=this;
}
Upvotes: 1
Reputation: 28403
I Think , you need to use Focus()
method for that.
private void btnOpenChildForm(object sender, EventArgs e)
{
ChildForm Form = new ChildFrom();
this.IsMdiContainer = true;
Form.MdiParent = this;
Form.Show();
Form.focus();
}
Upvotes: 2
Reputation: 415
Can you try this from http://www.codeproject.com/Articles/7571/Creating-MDI-application-using-C-Walkthrough :
ChildForm Form = ChildForm.GetChildInstance();
Form.MdiParent = this;
Form.Show();
Form.BringToFront();
Upvotes: 0
Reputation: 17003
look to this example it might solve your problem: http://www.codeproject.com/Questions/309232/Csharp-net-How-to-bring-a-MDI-child-form-to-the-fr
Upvotes: 1