⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formloader.cs

📁 ajax 框价.是个好工具.javascript 矿家.可以用在任何平台.
💻 CS
字号:
using System;using System.IO;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using Microsoft.CSharp;using System.CodeDom.Compiler;using System.Collections.Specialized;using System.Reflection;namespace FormExport {    public class FormLoader {        public static  Form LoadFromAssembly( String path ){            System.Console.WriteLine( "Trying to load from " + path );            Assembly thisAssembly;            thisAssembly = Assembly.LoadFrom( path );            Type [] typeArray = thisAssembly.GetTypes();            for( int i = 0 ; i < typeArray.Length ; i++ ) {                if ( typeArray[i].BaseType.FullName ==                                "System.Windows.Forms.Form" ) {                    System.Console.WriteLine( "Found a form" );                    ConstructorInfo constructorInfoObj =                        typeArray[i].GetConstructor( Type.EmptyTypes);                    return (Form)constructorInfoObj.Invoke( new Object[0] );                }                System.Console.WriteLine( "No forms found" );                return null;            }            return null;        }        public static  Form LoadFromSource( String path ){            System.Console.WriteLine( "Trying to load from " + path );            CSharpCodeProvider  cscp = new CSharpCodeProvider();            ICodeCompiler c = cscp.CreateCompiler();            CompilerParameters cp = new CompilerParameters();            cp.ReferencedAssemblies.Add("System.Drawing.dll");            cp.ReferencedAssemblies.Add("System.Data.dll");            cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())            {                cp.ReferencedAssemblies.Add(asm.Location);            }            CompilerResults cr = c.CompileAssemblyFromFile( cp, path );            int nRes = cr.NativeCompilerReturnValue;            if ( nRes != 0 ) {                System.Console.WriteLine( "Failed to compile " + path );                StringCollection sc = cr.Output;                for( int i = 0 ; i < sc.Count ; i++ )                    System.Console.WriteLine( sc[i] );                return null;            }            System.Console.WriteLine( "Loaded" );            Assembly thisAssembly;            thisAssembly = Assembly.LoadFrom( cr.PathToAssembly);            Type [] typeArray = thisAssembly.GetTypes();            for( int i = 0 ; i < typeArray.Length ; i++ ) {                if ( typeArray[i].BaseType.FullName ==                                "System.Windows.Forms.Form" ) {                    System.Console.WriteLine( "Found a form" );                    ConstructorInfo constructorInfoObj =                        typeArray[i].GetConstructor( Type.EmptyTypes);                    return (Form)constructorInfoObj.Invoke( new Object[0] );                }                System.Console.WriteLine( "No forms found" );                return null;            }            return null;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -