Assembly clientAssembly = Assembly.LoadFrom(  Application.StartupPath + @"\BuyerClient.exe" );
Type type=assembly.GetType(FormPurchaseDetail类型的全名);
MethodInfo methodInfo=type.GetMethod("Show");
object instance = Activator.CreateInstance(type,new Object[]{"23320"});
methodInfo.Invoke(instance,new object[]{});

解决方案 »

  1.   

    using System;
    using System.Reflection;namespace L
    {
    public class A
    {
    string _var;
    public A()
    {
    _var="Default";
    }
    public A(string v)
    {
    _var=v;
    }
    public string GetVar()
    {
    return _var;
    }
    }
    public class L
    {
    static void Main()
    {
    Assembly asm=typeof(A).Assembly;
    ConstructorInfo ci;
    A a; ci=typeof(A).GetConstructor(new Type[0]);
    a=ci.Invoke(new object[0]) as A;
    Console.WriteLine(a.GetVar()); ci=typeof(A).GetConstructor(new Type[]{typeof(string)});
    a=ci.Invoke(new object[]{"TheVar"}) as A;
    Console.WriteLine(a.GetVar());
    }
    }
    }
      

  2.   

    sheep2002(sheep2002):
    这样也不行的,参数不匹配:(
      

  3.   

    Object[] arguments = {"23320"};
      

  4.   

    Form formPurchaseDetail = (Form)clientAssembly.CreateInstance( "com.unc.pharmacy.BuyerClient.FormPurchaseDetail", false,          BindingFlags.CreateInstance,          null,               new object[] {"23320"}, null, null);
      

  5.   

    好用的,这是我程序里的代码,写在button2_Click事件里Assembly clientAssembly = Assembly.LoadFrom(  Application.StartupPath + @"\test1.exe" );
    Type type=clientAssembly.GetType("test1.Form4");
    MethodInfo methodInfo=type.GetMethod("Show");
    object instance = Activator.CreateInstance(type,new Object[]{"23320"});
    methodInfo.Invoke(instance,new object[]{});
    /////////////////////////////////////
    private string inPurchaseId;
    public Form4(string inPurchaseId)
    {
          InitializeComponent();
          MessageBox.Show(inPurchaseId);
    }
      

  6.   

    谢谢各位,仔细检查了一番,我写的也没有问题,而是在我调用的窗体类中需要数据连接,但在调用时由于不是从BuyerClient.exe的入口进入的,所以数据库连接字符串初始化失败导致错误:(谢谢各位!