MDI 窗体中打开子窗体的函数。

代码如下:
程序代码
  private void OpenChild(string Frmnamespace, string ChildTypeName)
        {
            int ret = 0;
            foreach (Form frm in MdiChildren)
            {
                if (frm.GetType().Name == ChildTypeName)
                {
                    frm.Activate();
                    ret = 1;
                    break;
                }
            }
            if (0 == ret)
            {
                string className = Frmnamespace + "." + ChildTypeName;
                Form Instance = (Form) Assembly.Load(Frmnamespace).CreateInstance(className);
                Instance.MdiParent = this;
                Instance.Show();
            }
        }
传入一个窗体,先检查这个窗体是不是有副本,如果有副本,则置前,否则新创建并显示.
使用方法:
程序代码
private void LbtUserManager_ItemClick(object sender, ItemClickEventArgs e)
        {
            OpenChild("OuterRingRoad", "frmUserManager");
        }
        private void MenuUserPopdemod_ItemClick(object sender, ItemClickEventArgs e)
        {
            OpenChild("OuterRingRoad", "frmUserPopdemod");
        }
        private void MenuCurrentTimeData_ItemClick(object sender, ItemClickEventArgs e)
        {
            OpenChild("ORRTLB", "frmNowVDIInfo");
        }
        private void MenuCarCheckConfig_ItemClick(object sender, ItemClickEventArgs e)
        {
            OpenChild("ORRTLB", "frmVDISetting");
        }

posted @ 2009-10-27 09:32  大漠银狐  阅读(256)  评论(0编辑  收藏  举报