I'm not sure whether you have resolved this or not but the code should look something like this:
C# Code:
private Form2 childForm;
private void ShowChildForm()
{
if (this.childForm == null || this.childForm.IsDisposed)
{
// Create a new child form and show it.
this.childForm = new Form2();
this.childForm.MdiParent = this;
this.childForm.Show();
}
else
{
// Activate the existing child form.
this.childForm.Activate();
}
}
Note that if there is not supposed to be more than one instance of a form then you can also have that form implement the Singleton pattern:
C# Code:
public partial class Form2 : Form
{
private static Form2 _instance;
public static Form2 Instance
{
get
{
if (_instance == null || _instance.IsDisposed)
{
_instance = new Form2();
}
return _instance;
}
}
private Form2()
{
InitializeComponent();
}
}
Then your code in the parent form becomes:
C# Code:
private void ShowChildForm()
{
Form2.Instance.MdiParent = this;
Form2.Instance.Show();
Form2.Instance.Activate();
}