一个可以从主应用程序启动的WinForms DLL

Boh*_*ohn 5 c# dll winforms

我创建了一个C#DLL,其中包含一些表单.(我需要它是一个DLL,而不是Windows应用程序.)如何将其作为Windows应用程序运行?我应该创建另一个应用程序并加载它吗?怎么样?我需要学习什么才能做到这一点?如果我应该更多地解释我的问题,请告诉我.

cod*_*ife 6

如果您使用的是VS 2008:

首先,创建一个Windows窗体应用程序项目.如果您不打算使用它,可以删除创建的默认表单(Form1.cs).

在Solution Explorer中,右键单击References并选择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****]);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果DLL包含断开连接的表单,您可能需要在winforms项目中添加一个类来协调表单行为.