0

I have a solution with a Class Library and a Windows Forms App. I added a 'Test' Windows Forms App for testing purposes.

In the 'Test' project the Class Library controls appear in the Toolbox as expected. The controls of the WinForms app only appear after a 'Show All' and are grayed out.

Is it possible to access the controls belonging to the original WinForms application from the Toolbox?

Using Visual Studio Community 2017,

I tried:

  1. Closing, reopening, cleaning and rebuilding the solution.
  2. Adding References.
  3. Restarting Visual Studio.
  4. 'Reset Toolbox'.
  5. Checking 'Automatically Populate Toolbox'.
  6. Changing the WinForms App Output type to Class Library.

Point 6 works so this behavior may actually be by design. It wasn't in the past, so please let me know.

Tonn
  • 1
  • 3
  • Have you defined your Custom Controls classes as `public`? Or you have just `class MyControl : SomeStandardControl { }`? – Jimi Jan 27 '19 at 18:11
  • Also, have you set the dependency in the Solution `properties -> Common Properties -> Project Dependencies` of the starting (WinForms) project, setting it to the Class Library project? When you do this, unless you have errors in Custom Controls class structure, you'll see the controls in the WinForms project toolbox (when you have a Form opened in the Designer, that is). – Jimi Jan 27 '19 at 19:02
  • Yes, the custom controls are public. – Tonn Jan 27 '19 at 20:32
  • Referencing the Class Library controls isn't the issue. Referencing the controls in the original WinForms application is. I used to be able to do this in the past, hence my confusion. – Tonn Jan 27 '19 at 20:34
  • Can you post the code of the Controls' constructors? Have you set the other options as described? I don't know what this means: *Referencing the Class Library controls*. You don't have to reference the controls. When you have a Control in a class library, you just need to drop it on a Form from the Toolbox (or build it in code) as usual. Also, check the bitness of both projects: it must be the same. – Jimi Jan 27 '19 at 20:37
  • The Class Library is fine. The controls in the Class Library are fine. They all drop from the Toolbox and work nicely. No problem there. Next, I have a control in a WinForms project which drops from the Toolbox and works nicely, as long as you stay within it's own project. Now, I want to drop and use that control from another WinForms project, but then I only get a grayed out version of the control in the Toolbox.. – Tonn Jan 27 '19 at 20:59
  • Did you add this second WinForms test Project to the previous Solution (which now has 3 projects) or to a different Solution? – Jimi Jan 27 '19 at 21:08
  • To the previous solution. – Tonn Jan 27 '19 at 21:10
  • Then, have you followed the steps described in my second comment, adding a reference to the Class Library in the second WinForms Project? Note that for a second Project, you need to set the reference in the Project manually, So, both in the Solution Properties and the Project Properties (`Project->References->Projects -> Your Class Library`). – Jimi Jan 27 '19 at 21:12
  • (I am not allowed to move this discussion to chat) All references are set. Also, I duplicated this problem in a solution with only two WinForms projects and nothing else (no Class Library). So, it's really about a control in another WinForms project only showing up grayed out in the current WinForms projects Toolbox. – Tonn Jan 27 '19 at 21:29
  • Why would you do that? You can have a custom control belonging to a WinForms project in another WinForms project if you change one of the two to a Class Library project. Don't do that. If you need to *share* components, use an actual Class Library and reference it in all the WinForms Project you need. – Jimi Jan 27 '19 at 22:09

1 Answers1

1

See this answer

You need to choose Windows Form (.NET Framework) as Project type while creating the project. Not the other one which is just Windows Form

sribasu
  • 680
  • 2
  • 6
  • 24
  • Thanks for posting. Using VS2019 now, I don't have the option 'Windows Form'. I have the options 'Windows Forms App (.NET Framework)' and 'Windows Forms App (.NET)'. The option with 'Framework' in it still does not work and also is no longer visible in the Toolbox. The option without 'Framework' however does show up in the Toolbox and the controls can be used directly. I have determined this to be a purely VS editor related matter. Not worth the time for new projects but can be quite a nuisance for legacy projects when you are not allowed to change the project structure. – Tonn Jun 26 '21 at 21:40