Private void button1_Click(object sender, EventArgs e) The code will look similar to this: using System Reference the form in the DLL, firstly with using DLLForm, and code to load the DLL form from a button. In the DLLFormTest project add a reference to the DLLForm Class Library.ĭrop a button onto the main EXE's form (in this tutorial Form1 in the DLLFormTest project). Delete the Class1 file from the DLLForm project, it won't be used. Change the new renamed DLL form's text property as well, e.g. Accept the Visual Studio option to rename all references to the renamed form. to MyForm from Form1, so that you do not get confused with the form in the.
dll project (here called DLLForm) to add a Windows form, using Add then New Item (or add a new form via the Project menu). Put a WinForm in the DLL and Add References exe, here it is called DLLFormTest, then add a new Class Library project called DLLForm to the new solution (using Add and New Project). In Visual Studio create a test app for the. The WinForm is located in a Class Library project, which compiles into a DLL.
exe is going to load a WinForm from a DLL. Start with a Test Program and Class Libraryįor this tutorial a Windows.
However, WinForms can be added to dlls to help break up a bigger program into more manageable chunks. Lots of developers add Windows forms (WinForms) to the. Then, especially for large programs with lots of functionality, there are library files that contain other code the main. For Windows apps there is the main executable, or. When it comes to programming an app, try and keep the apps functions contained into small separate units, it'll help with future development and help to avoid spaghetti code. This tutorial assumes you can create and start a WinForms project in Visual Studio, if not see the article Hello World in C#, A Starting WinForms Example This can help with an apps design, maintenance, and testing, and when adding new features, by breaking up a large project into more manageable chunks. This article covers the programming of Windows forms and dialogs so that they are located in a Windows DLL (dynamic link library). Forms and Dialogs in a Windows DLL with C Sharp