与WinForms的一个DLL,可以从主应用程序启动 [英] A DLL with WinForms that can be launched from A main app
问题描述
我已经创建了具有一定形式中有一个C#DLL。 (我需要它是一个DLL,而不是一个Windows应用程序。)
我怎么可以运行它作为Windows应用程序?我应该创建另一个应用程序并加载它?怎么样?什么是我需要学习这样做呢?
请让我知道,如果我要解释一下我的问题。
I have created a C# DLL that has some forms in it. ( I needed it to be a DLL, not a Windows Application.) How can I run it as a Windows App? Should I create another app and load it? How? What do I need to learn to do that? please let me know if I should explain more about my question.
推荐答案
如果你使用VS 2008:
If you're using VS 2008:
首先,创建一个Windows窗体应用程序项目。您可以删除所创建(Form1.cs中),如果你不打算使用它的默认窗体。
First, create a Windows Forms Application project. You can delete the default form that's created (Form1.cs) if you don't plan to use it.
在Solution Explorer中,在参考并选择添加引用。这是您添加自定义设计的C#DLL点
In the Solution Explorer, right-click on the References and select Add Reference. This is the point where you add your custom designed C# DLL.
现在开放的Program.cs,并在做出以下变化:
Now open Program.cs, and in make the following change:
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****]);
}
}
}
如果这个DLL中包含断开的形式,你可能需要在WinForms项目协调行为形式添加一个类。
If the DLL contains disconnected forms, you'll probably need to add a class in the winforms project to coordinate the forms behavior.
这篇关于与WinForms的一个DLL,可以从主应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!