none
load a child form into a MDI Form from another Class RRS feed

  • Question

  • I have a Main Form call frmMain and it is set a MDI, One Form called frmClientInfo and a class call cAction.
    The main form has a menu button called mnuClientInfo.
    When I click the menu button it calls a function in cAction call AddNewClient.

    I have this:

    {

    {

    {


    what is wrong

     

    if (frmClientInfo.Visible)

    {

     

    frmClientInfo.Focus();

    }

     

    else

    {

     

    frmClientInfo.MdiParent = frmMain;

     

    frmClientInfo.Show();

    }

    }

    }

    }

    }

    }


    Sunday, November 29, 2009 5:39 AM

Answers

  • Hi,

    first of all Is frmClientInfo is a reference or a type?

    I think in this scenario it's a type,

    that causes the problem could you try.

                frmClientInfo refOfFrmClientInfo = null;
                foreach (Form f in this.MdiChildren)
                {
                    if (f is frmClientInfo)
                    {
                        refOfFrmClientInfo =f;
                        break;
                    }
                }
    
                if (refOfFrmClientInfo==null)
                {
                    frmClientInfo f = new frmClientInfo();
                    f.MdiParent = this;
                    f.Show();
                    
                }
                else
                {
                    refOfFrmClientInfo.BringToFront();
                    refOfFrmClientInfo.Focus();
                }
    Sunday, November 29, 2009 5:47 AM