Form existance

  • Thread starter Thread starter Travis Scott
  • Start date Start date
T

Travis Scott

Hi all,

Just wondering how I can check if a particular class of
form is loaded and its visibility. I want to ensure that
an MDI form doesn't open a child more than once.

TIA
Regards,
Travis Scott
 
Hi Travis,
You can use the code below to achieve the functionality you desire. I am
trying to open this from from the click event of a menu item. I then loop
over to see if there is already a form of the type I am trying to open in my
MDIChildren collection. If not then open it else do nothing.

Hope this helps.

private void menuItem2_Click(object sender, System.EventArgs e)

{

OpenNewForm(typeof(Form2));

}

private void OpenNewForm(Type ChildForm)

{

Form NewForm = null;

foreach(Form form in this.MdiChildren)

{

if(form.GetType().Equals(ChildForm))

{

NewForm = (Form)form;

NewForm.MdiParent = this;

NewForm.Show();

}

}

if(NewForm == null)

{

NewForm = (Form) Activator.CreateInstance(ChildForm);

NewForm.MdiParent = this;

NewForm.Show();

}

}
 
Back
Top