Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

c# - A DLL with WinForms that can be launched from A main app

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you're using VS 2008:

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.

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.

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****]);
        }
    }
}

If the DLL contains disconnected forms, you'll probably need to add a class in the winforms project to coordinate the forms behavior.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...