zoukankan      html  css  js  c++  java
  • 利用反射动态(运行时)加载窗体

    文件名,窗体名,参数
            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;
            }

  • 相关阅读:
    php smarty使用..
    深圳面试!
    jQuery 源码分析..
    jQuery 使用技巧!!!
    TOMCAT 访问过程...
    准备使用Delphi调用WCF
    Delphi 中Format的字符串格式化使用说明(转载http://hi.baidu.com/test__123/blog/item/e3bba1599d717a2d2834f092.html)
    电脑启动程序自动启动
    判断输入字符串是否等效Int32位数字的两种方法
    vs2005 快捷键
  • 原文地址:https://www.cnblogs.com/cwfsoft/p/1759353.html
Copyright © 2011-2022 走看看