Pergunta

I am working on MDI app which have Child Forms. I have to show Child Window once a certain conditions is met.

I created a separate Class named clsDashbord having method loadDashboard() which is supposed to load frmDashboard already designed. Code is given below:

 public void loadDashboard(String userName)
        {
            _Dashboard = new frmDashboard();
            _Main = new frmMDI();
           // _Dashboard.MdiParent = _Main;
            _Dashboard.Text = userName;
            _Dashboard.Show();

        }

Form does not show up if I set MDIParent to Main which is instance variable of MDI Form otherwise it gets displayed. How to do it?

Foi útil?

Solução

It looks more like a scoping problem by looking at line '_Main = new frmMDI();'

follow these steps:

  1. create a class named 'ReferenceTable'
  2. create a static variable named _Main in ReferenceTable
  3. set ReferenceTable._Main = new frmMain(); // in Program.cs
  4. set childform.Parent = ReferenceTable._Main //in all your child form code before calling Show() or showDialog() methods
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top