这已经回答了多次:
从Killercam:
// Execute the method from the requested .dll using reflection (System.Reflection).
Assembly DLL = Assembly.LoadFrom(strDllPath);
Type classType = DLL.GetType(String.Format("{0}.{0}", strNsCn));
object classInst = Activator.CreateInstance(classType, paramObj);
Form dllWinForm = (Form)classInst;
dllWinForm.ShowDialog();
从Code4life
在Solution Explorer中,引用单击鼠标右键,选择Add Reference。这是您添加自定义设计的C#DLL的地方。
现在打开Program.cs文件,并进行以下更改:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ****your DLL namespace here****
namespace WindowsFormsApplication2
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new [****your startup form (from the DLL) here****]);
}
}
}
这个答案不是很好吗? http://stackoverflow.com/questions/2822326/a-dll-with-winforms-that-can-be-launched-from-a-main-app – Dayan