WinForms DLL that can be run from the main application

I created a C # DLL in which there are some forms. (I need this to be a DLL, not a Windows application). How can I run it as a windows application? Should I create another application and download it? How? What do I need to learn this? please let me know if I tell you more about my question.

+4
source share
3 answers

If you are using VS 2008:

First create a Windows Forms application project. You can delete the default form (Form1.cs) if you do not plan to use it.

In Solution Explorer, right-click the Links link and select Add Link . This is where you add your custom C # DLL.

Now open Program.cs and 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 unrelated forms, you probably need to add a class to the winforms project to coordinate the behavior of the forms.

+5
source

You can add forms to your DLL, and then create a public static function in the DLL that calls Application.Run with the form.

Then you can call this public static method from the C # application project (after adding the link to the DLL).

+3
source

You can run it using RunDll32 , however you may need to tweak the dll a bit before it works. You may need to put Application.Run at the entry point. this way you do not need to compile another application to use it.

the code below is untested, but I think it should work.

 public static void myDllEntryPoint() { Application.run(new MyFormInDll()); } 

Run the application as

 rundll32.exe myDll.dll,myDllEntryPoint 
+3
source

Source: https://habr.com/ru/post/1309599/


All Articles