从数据库中查询出命名空间和formname动态打开窗体

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using SQLHelperTool;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Runtime.Remoting;



namespace 基于角色的文件管理
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataTable dt = new DataTable();
        private void button1_Click(object sender, EventArgs e)
        {
            string sql = "select * from RoleRight,SysFun,UserInfo where UserInfo.RoleId=RoleRight.RoleId and RoleRight.NodeId=SysFun.NodeId and UserId='admin'";
            dt = DbHelperSQL.SqlDataAdapter(sql);
            dataGridView1.DataSource = dt;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            foreach (DataRow item in dt.Rows)
            {
                if (item["NameSpacName"].ToString() != "")
                {
                    string formName = item["FullFrmName"].ToString();
                    ObjectHandle objectHandle = Activator.CreateInstance(null,item["NameSpacName"].ToString() + "." + item["FullFrmName"].ToString());
                    Form form = (Form)objectHandle.Unwrap();
                    form.ShowDialog();
                }
            }
        }
    }
}
原文地址:https://www.cnblogs.com/anbylau2130/p/2721894.html