Only one MDI child at a time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an MDIParent form and when I click on a menu item, it opens up a child
form. However, if I click the menu item again, it opens up a second version
of the form. How can I make sure that only one version of this form is open
at a time?
 
cashdeskmac said:
I have an MDIParent form and when I click on a menu item, it opens up a child
form. However, if I click the menu item again, it opens up a second version
of the form. How can I make sure that only one version of this form is open
at a time?


When you click on the menu to open an MDI child, check if such a child already exists.


bool bOpen = false;
foreach (Form f in this.MDIChildern)
if (f.Name == "YourFormName")
bOpen = true;
if (!bOpen)
*Open Your Form*


Hope it helps,
Andrey
 
MuZZy said:
if (f.Name == "YourFormName")

Better to use

if (f is YourFormName)

that way if you mistype YourFormName the compiler will pick it up.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top