使用反射加载MDI窗体

使用DevExpress.XtraTabbedMdi.XtraTabbedMdiManager控件来加载MDI窗体

	/// <summary>
        /// 加载窗体
        /// </summary>
        /// <param name="ChildTypeString">窗体类型名称</param>
        /// <param name="args">参数</param>
        public void OpenMDIWindow(string ChildTypeString,object[] args)
        {
            if (string.IsNullOrEmpty(ChildTypeString))
                return;
            var fullName = String.Format("{0}.{1}", GetType().Namespace, ChildTypeString);
            if (ContainMDIChild(fullName))
                return;

            // Create data type using type string
            Type typForm = Assembly.GetExecutingAssembly().GetType(fullName);
            if (typForm == null)
                return;
            // Create object using type's "InvokeMember" method
            Object obj = typForm.InvokeMember(
                null,
                BindingFlags.DeclaredOnly |
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Instance | BindingFlags.CreateInstance,
                null,
                null,
                args);

            // Show child form
            if (obj == null)
                return;
            Form myChild = obj as Form;
            myChild.MdiParent = this;
            myChild.WindowState = FormWindowState.Maximized;
            myChild.Show();
        }
	/// <summary>
        /// 判断MDI中是否已存在当前窗体
        /// </summary>
        /// <param name="ChildTypeString">窗体类型名称</param>
        /// <returns></returns>
        private bool ContainMDIChild(string ChildTypeString)
        {
            foreach (Form f in MdiChildren)
            {
                if (f.GetType().ToString() == ChildTypeString)
                {
                    f.Select();
                    return true;
                }
            }
            return false;
        }


你可能感兴趣的:(反射)