How to set MDIParent property of Child form in nonMDI Class?

爱⌒轻易说出口 提交于 2019-12-08 06:24:40

问题


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:

  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


来源:https://stackoverflow.com/questions/15677629/how-to-set-mdiparent-property-of-child-form-in-nonmdi-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!