Skip to content

Child form appears again after checking dialog result if ok

Mark Christian Baliling

Asked Apr 15, 2008, 1:34 PM EDT3 answers
Share
LinkedInX

Hi,

I've got this child form that when i try to check it in main form if (chldfrm.ShowDialog() == DialogResult.OK, and if true the child form is shown again. Though the passed value from child form into the main form is shown after the child form appears. Can any one help?

Thanks in advance.

3 Answers

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

  • Niradhip Chakraborty
    0
    Can you please explain it in details with your code. Did you mean once a child form is opened and again click on ok button it shows a duplicate child form inspite of focusing it in old child form???
    0
  • Niradhip Chakraborty
    0

    Try this out. The following code will prevent you to open duplicate form.
     
            foreach (Form frmchild in this.MdiChildren)
                {

                    if (frmcompany is chldfrm)
                    {


                        frmchild.Show();
                        frmchild.Focus();
                       
                        return;

                    }

                }

                chldfrm frmchild1 = new chldfrm();
              
                this.AddOwnedForm(frmchild1);

                frmchild1.MdiParent = this;

                frmchild1.Show();
      

    0
  • 0

    James,

    Your code works, however it took me a couple of minutes how to work it out.

    Thanks!

    0