[反射]利用Activator.CreateInstance(type)实例化表单

通常我们在做BS项目树形菜单的,判断好权限后点击节点URL跳转到指定的页面

最近好玩写写WINFORM,点击节点从数据库中读取类型 进行实例化,不认识!!!

上网查查看到这个方法Activator.CreateInstance(type)

就改改代码了:

            try
            {
                Type type = Type.GetType("frmclass");
                if (type != null)
                {
                    Form newFrm = (Form)Activator.CreateInstance(type);
                    newFrm.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                throw ex; 
            }


 

你可能感兴趣的:(exception,数据库,null,url,WinForm)