Click here to Skip to main content
14,576,041 members
Rate this:
Please Sign up or sign in to vote.
See more:
I used a freely available User Control solution project as template to create a new User Control from scratch for myself. As far as I can see my project has everything important included when I compare it with the template project, but it seems like I did something fundamental wrong. When I hit Debug in the template project(Output Type is Class Library), VS runs a test application called UserControlTestContainer. When I hit Debug in my project VS simply shows the error "Output Type of Class Library cannot be started directly". The only thing I could imagine is that I eventually used the wrong Project template. When I want to create a new UserControl, is Windows Forms App the wrong choice?. Otherwise I really don't know the problem.

What I have tried:

Could it be that Windows Forms Control Library will be the correct Project type?
Updated 22-Nov-19 5:14am
0x01AA 22-Nov-19 11:00am
Most probably:
The original solution has a test project which is set as default project to run

While your project has only the class library project, which as you know can not be startet without a host application.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

No, you don't create a project type in order to create a UserControl: you can add it to any assembly, but for reusable controls, I tend to create a Class Library just to hold them, and a WinForms project to Test them - because you can;t execute a Class library directly. Once you have the assembly created, just add a UserControl to the Project and build it all up.

Then add a reference to the ClassLibrary in the Test project and drag and drop the UserControl onto the form design surface.
Member 13920025 22-Nov-19 11:42am
Thanks for explaining your method. The other solution with Windows Forms Control Library will work fine too. I tested this now. With this Project type I can run the test application in Debug Mode independently from Output type ClassLibrary or Application to test my User Control. Then I can build the Release file .dll or .exe and add the new User Control to the Toolbox as new Toolbox Item in another solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100