Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
Posted
Updated 22-Nov-19 5:14am
v5
Comments
[no name] 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

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.
 
Share this answer
 
Comments
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900