User Controls not showing up in the toolbox

2019-01-21 21:19发布

I have some UserControls that I created in ProjectA. I have ProjectB that has a windows form that I want to put the controls on. Both of these projects are in a single solution. There's a reference to ProjectA from ProjectB so it can "see" the UserControls.

However, the UserControls do not show up in the toolbox for me to drag to the windows form.

I've tried rebuilding. I've also deleted the 'bin' directory to force a rebuild-all.

How do I get VS2008 to populate the toolbox with my UserControls?

29条回答
一纸荒年 Trace。
2楼-- · 2019-01-21 21:48

For someone who might be working with ToolStripItems (e.g. ToolStripStatusLabel), to actually get your derived control to show up in the dropdown menu (such as the one from StatusStrip), you need to set the class to public then build the solution.

Also don't forget the designer attribute for your class, something like this:

using System.Windows.Forms.Design;

[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.StatusStrip)]
public class MyStatusLabel : ToolStripStatusLabel
{
}

Took me a while to get it right. Hopefully this can save someone else's time.

查看更多
老娘就宠你
3楼-- · 2019-01-21 21:49

Here was my problem: I had added a new constructor for my control which accepted a few arguments, but I had not explicitly re-declared the empty constructor! The toolbox can only include controls which have empty constructors. In general, when you are designing a class in vb, it has an empty constructor defined implicitly (meaning you don't need to declare one). BUT, as soon as you start designing your own constructors, this empty constructor disappears, so you need to explicitly redefine it in your code! Anyways, I realize most experienced vb coder's already know all this, but hopefully this can help some newbies like myself :).

查看更多
▲ chillily
4楼-- · 2019-01-21 21:51

If you still can't find why your vstudio toolbox is not populated with your usercontrols. Then you can debug vstudio with another visual studio. Here you can find how.

查看更多
做个烂人
5楼-- · 2019-01-21 21:51

Symptom 1: The Design Views for Form, UserControl, & Component were FAILING!

  • My Form design view was failing w/ the msg "can not find 'User Control'."
  • If I could get the Form design view to work it was very unstable & corrupted all to hell w/ any change.

Symptom 2: The UserControl & Component in the Toolbox

  • Were grayed out in the Toolbox & showed a garbled name
  • "Choose item" in the Toolbox context menu showed garbled name & no namespace

Solution: Set scope to Public in the vb behind UserControl, & Component

查看更多
放荡不羁爱自由
6楼-- · 2019-01-21 21:53

My control was public, it was checked in the 'Choose Toolbox Items' dialog, but it was still not showing up.

This is what finally worked for me:

Right click somewhere in the Toolbox and click 'Choose Items'. When I found my item it was already checked. I then unchecked the item and clicked okay. Next I right clicked the toolbox again and searched for my item... it was gone, so I clicked Browse, navigated to the obj/x86/debug folder and selected my exe. The item was then added correctly to the toolbox.

I think it's a VS bug.

查看更多
放我归山
7楼-- · 2019-01-21 21:54

I was trying to build a x64 only application, so my platform target was set to x64 of course.

However, even in 2016, Visual Studio (devenv.exe) is still a 32 bit process and it cannot load 64 bit assemblies. To check the bitness of your Visual Studio, open Task Manager and check for *32 at the name of the process.

Workaround to see the Controls in the toolbox: set the platform target to Any CPU in the project settings. Do that for Debug and Release build, if necessary.

查看更多
登录 后发表回答