问题
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?
回答1:
It looks more like a scoping problem by looking at line '_Main = new frmMDI();'
follow these steps:
- create a class named 'ReferenceTable'
- create a static variable named _Main in ReferenceTable
- set ReferenceTable._Main = new frmMain(); // in Program.cs
- set childform.Parent = ReferenceTable._Main //in all your child form code before calling Show() or showDialog() methods
来源:https://stackoverflow.com/questions/15677629/how-to-set-mdiparent-property-of-child-form-in-nonmdi-class