加载dll

加载dll

private void btn_LoadDll_Click(object sender, EventArgs e)
        {
            pnl_plugins.Controls.Clear();          
            string pluginPath = Application.StartupPath + @"\Plugins\";
            if (!System.IO.File.Exists(pluginPath + "Plugin.dll"))
            {
              MessageBox.Show("没有匹配的插件","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            string data = "Plugin.Part";
            try
            {
                // 加载控件 
                System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(pluginPath + "Plugin.dll");
                // 获得类(型) 
                Type type = assembly.GetType(data, false, true);
                Object obj = Activator.CreateInstance(type);
                System.Windows.Forms.Control control = obj as Control;
                pnl_plugins.Controls.Add(control);
            }
            catch
            {
                MessageBox.Show("插件加载失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

 

 

 

 

posted on 2013-01-07 21:23  %幻#影%  阅读(159)  评论(0编辑  收藏  举报

导航