Skip to content

MDI project

Victor Baleishis

Asked Mar 21, 2006, 11:58 AM EST2 answers
Share
LinkedInX

HI!

I have a little problem... I have MDI project: one Parent and two different Child forms. And I want that user can create only one copy of each Child form at time. I have a verification before creating (simplified version):

Code
if(one_of_child_form == null)
   this_form_i_create();
And code for closing Child forms (in Parent form):
one_of_child_form.Close();
this_form = null;

So far all works OK, but if I close any Child form with it controls (I've button "Close", or by Click on standart cross), Parent form don't understand it. It think that I already have this Child form, because this Child form is not null. How can I tell from Child form to Parent form that "I had a good time with you, but I'm closing now, thatswhy I = null"???
Or is there other way how it make or other return value?

Thanks!

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You can try to use parent property Form[] MdiChildren. This is an array of created child forms. Before you create an instance of some child form you may look at this array to find pointer to an object of target class-form as follow:
    bool exist_child = false;
    foreach (Form frm in this.MdiChildren)
    {
      if (frm.GetType() = typeof(MyChildForm_1))
        exist_child = true;
    }
    if (exist_child)
     this.CreateFormOne();

    Also, you can use a singleton pattern for child forms.
    0
  • 0

    Yeah, it helps. Thanks Alexandr!

    0