Connecting Tech Pros Worldwide Forums | Help | Site Map

MDI Form App

Newbie
 
Join Date: Sep 2008
Posts: 8
#1: Sep 25 '08
I have created a windows app form project.

I have 3 forms, the first one I have set to be MDI Parent, the other two are Child.

When I click a button to open the two child forms, how can I stop them from opening more than once.

As it is just now, the form opens however many time I click the button, but I only want them to open once.

insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#2: Sep 26 '08

re: MDI Form App


What I do is make the child forms members of the parent form. Private global variables if you will:
Expand|Select|Wrap|Line Numbers
  1. public class Form1 : Form
  2. {
  3. private Form2 f2;
  4.  
  5. public Form1()
  6. {
  7. InitializeComponent();
  8. f2 = new Form2()
  9. }
  10. }
And when I want to show it, I check to see if f2 has been disposed. If it has, I make a new instance and show it, otherwise, I just focus on it.

Note: I just typed this code in by hand. I didn't copy+paste from an existing project. This is just an example.
Reply