• 利用反射动态(运行时)加载窗体


    文件名,窗体名,参数
            private int Run_WinForm(string filename, string myfrmname, DataTable mydtmsg)
            {
                Assembly vAssembly = null;
                if (string.IsNullOrEmpty(filename) == true)
                {
                    vAssembly = Assembly.GetExecutingAssembly();
                }
                else
                {
                    if (System.IO.File.Exists(filename) == true)
                    {
                        vAssembly = Assembly.LoadFrom(filename);
                    }
                    else
                    {
                        cwfIosys.ioCtrl.MsgShow("程序集文件不存在!\r\n" + filename);
                        return 0;
                    }
                }
                System.Globalization.CultureInfo gcnull = null; object[] objnull = null;
                Binder binull = null;
                object vTemp = null;
                object[] objstr = new object[1];
                objstr[0] = mydtmsg;
                vTemp = vAssembly.CreateInstance(myfrmname, true, BindingFlags.Default, binull
                                 , objstr, gcnull, objnull);
                try
                {
                    if (vTemp == null && appCtrl.appAssembly != null)
                    {
                        vAssembly = appCtrl.appAssembly;
                        vTemp = vAssembly.CreateInstance(myfrmname, true, BindingFlags.Default, binull
                         , objstr, gcnull, objnull);
                    }
                    else
                    {
                        if (appCtrl.appAssembly == null)
                        {
                            cwfIosys.ioCtrl.MsgShow("appCtrl.appAssembly is Null"
                                + "\r\n  Assembly vAssembly"
                                + "\r\n  vAssembly = Assembly.GetExecutingAssembly();" +
                                "run_winform!", "No vAssembly!", 2, 1500);
                        }
                    }
                }
                catch (Exception cw)
                {
                    if (cw.Message.IndexOf(myfrmname) >= 0)
                    {

                        vTemp = vAssembly.CreateInstance(myfrmname);
                    }
                    else
                    {
                        MessageBox.Show(cw.Message);
                        cwfIosys.ioCtrl.MsgShow(cw.Message + "\r\n" + cw.GetBaseException().ToString());
                    }
                }
                if (vTemp != null)
                {
                    //  ((System.Windows.Forms.Form)vTemp).MdiParent = appCtrl.appMainfrom;
                    ((System.Windows.Forms.Form)vTemp).Show();
                    // ((System.Windows.Forms.Form)vTemp).Name = wname.Replace(".", "_");
                    //    appCtrl.appMainfrom.Load_WorkToolStripStatus(wname.Replace(".", "_"), title);
                    //   ((System.Windows.Forms.Form)vTemp).FormClosed += new System.Windows.Forms.FormClosedEventHandler(appCtrl.frmsys_FormClosed);
                    return 1;
                }
                return 0;
            }

  • 相关阅读:
    MySQL系列(二)
    MySQL系列(一)
    RabbitMQ的安装部署
    RabbitMQ原理介绍
    消息中间件metaq
    消息中间件之zookper安装部署
    ZooKeeper基本原理
    消息中间件剖析
    了解Node.js
    windows下使用Git
  • 原文地址:https://www.cnblogs.com/cwfsoft/p/1759353.html
Copyright © 2020-2023  润新知