I've been building DLL class libraries in C#, used as add-ons to an application which provides a Custom API. Up until now they've included mostly interfacing with databases, calculations, disk operations and so forth. I'm curious to know if I can build and display a Windows Form, displaying text boxes, buttons and so forth, inside a DLL Class Library?
I tried:
using System.Windows.Forms;
But that namespace is not recognized.
Thanks for the input.
What I find works best for me is to create a new Windows Forms project, and then go to the project properties and change it to a class library. This way, you can right click on folders in the solution explorer and all the WinForms items appear just as if it were still a WinForms project, but it's a class library. This also works with WPF applications.
if the New form is already in a Windows project that has to stay windows application..
try these Steps not sure if this is what you want... hope it helps.
Yes, you can. You need to add a reference to
System.Windows.Forms
in the class library project (right-click on project -> Add -> Reference)You can definitely use Windows Forms inside your class library. There are few scenarios:
You are adding a form to the library using FormDesigner. You can right click on project name, click on Add and then in Windows form. It should add required References for your form
You are copying a form from other project. In this case the Visual Studio will not be able to identify the form and will show it as simple C# source file. In this case right click on References under the project in Visual Studio. Click on Add References and select
Framework
from left pane. SelectSystem.Windows.Form
andSystem.Drawing
and click Ok. This should make the form understandable to Visual Studio and you can design it edit it using Form Designer.System.Windows.Form
in your project withusing System.Windows.Form;
statement.