简体   繁体   中英

My custom user control is grayed out in toolbox

I have a solution that includes two projects. My main project is a windows form and the other project includes two user controls that I created. I have a test form in the second project, and there I have no problem using the user controls from the toolbox. However, in my main project I cannot use the user controls. I've found various 'solutions' online and tried them all with no success. The problem is, the controls ARE in the toolbox, they are just grayed out. I have:

  • Checked that both projects use the same .NET framework
  • Checked that autopopulate setting for the toolbox is true
  • Referenced the user control project
  • Have them both in the same solution
  • Rebuilt my project and solutions and restarted VS multiple times
  • Reset my toolbox
  • Clicked "choose items" and made sure the controls were checked

NOTE: If I create the user control programmatically, it compiles, shows up and works perfectly fine on run! I want it to show up in the designer though and not be gray in the toolbox.

Problem solved by going to the project (with the user controls) and changing the Output type to "Class Library" this builds a dll instead of an exe. Rebuild the solution and controls were in the toolbox.

确保要添加的控件是Public类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM