用户控件不显示在工具箱中

时间:2021-02-14 03:57:35

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.

我在ProjectA中创建了一些用户控件。我有ProjectB,它有一个windows窗体,我想把控件打开。这两个项目都在一个解决方案中。有一个来自ProjectB的对ProjectA的引用,这样它就可以“看到”用户控件。

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

但是,UserControls没有显示在工具箱中,我可以拖到windows窗体。

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

我试着重建。我还删除了“bin”目录以强制进行重新构建。

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

如何使用UserControls填充工具箱?

29 个解决方案

#1


80  

Check this setting:

检查这个设置:

Tools > Options > Windows Forms Designer > General : AutoToolboxPopulate

工具>选项> Windows窗体设计器>通用:autotoolbox填充

It should be set to True for this to work.

它应该被设置为正确的工作。

#2


29  

  1. Build your project to make sure it compiles.

    构建您的项目以确保它编译。

  2. With the form that you want your user control on, open the toolbox, right click and select "choose items"

    使用您希望用户控件打开的表单,打开工具箱,右键单击并选择“选择项”

  3. Browse to your .exe or dll that you compiled in step 1.

    浏览到您在步骤1中编译的.exe或dll。

  4. make sure that your user control has a tick next to it, press OK.

    确保您的用户控件旁边有一个勾号,按下OK。

  5. Your user control should appear in the toolbox, so drag it onto your form.

    您的用户控件应该出现在工具箱中,因此将它拖到窗体上。

This is adapted from Calanus's answer to a similar question.

这是根据Calanus对类似问题的回答。

#3


18  

In my case, the AutoToolboxPopulate was already set (Visual C# 2010 Express).

在我的例子中,AutoToolboxPopulate已经设置好了(Visual c# 2010 Express)。

However, I had to activate "Show All" from the properties of the Toolbox (right click) to actually see my new user controls.

但是,我必须从工具箱(右击)的属性中激活“显示全部”,以实际看到我的新用户控件。

#4


11  

Up until now, I had no problem with usercontrols not showing in the toolbox. Build the project and it just shows up. Then today not working. After a search I went through following but still no joy.

到目前为止,我对没有显示在工具箱中的用户控件没有问题。构建项目,它就会出现。然后今天不工作。搜寻之后,我继续追寻,但仍然没有快乐。

  • Tools > Options > Windows Forms Designer > General : AutoToolboxPopulate
  • 工具>选项> Windows窗体设计器>通用:autotoolbox填充
  • Tools > Options > Text Editor > XMAL > Misc : AutoToolboxPopulate
  • >选项>文本编辑> XMAL > Misc: AutoToolboxPopulate。
  • Reset the VS settings to default
  • 将VS设置重置为默认设置

So after a few hours of messing around trying to get it to work with no success, I created a new WPF windows project accepting the default name and added a usercontrol. Built the project and the user control appeared as it always had.

因此,在花了几个小时试图让它工作并没有成功之后,我创建了一个新的WPF windows项目,接受默认名称并添加了一个usercontrol。构建了项目,用户控件一如既往地出现。

I then thought that something might be wrong with my project or wpf window file. Removed the project, created a new one and added a new control. Built the project but it didnt work.

然后我认为我的项目或wpf窗口文件可能有问题。删除项目,创建一个新项目,并添加一个新控件。建造了这个项目,但没有成功。

The only thing I did different was choose a name for the project, which I included a space in the name "WPF Application".

我做的唯一不同的事情是为项目选择一个名称,其中包括一个名为“WPF应用程序”的空间。

Removed the project again and created a new one again called "WPFApplication" without the space and added a user control. Built it and the user control showed up.

再次删除该项目,并创建了一个新的名为“WPFApplication”的项目,并添加了一个用户控件。构建后,出现了用户控件。

If you want usercontrols to show up automatically in the toolbox on build, dont use spaces in the project name. Hopefully this post save's someone else a ton of wasted time.

如果您希望用户控件在build上的工具箱中自动显示,请不要在项目名称中使用空格。希望这篇文章能让别人省下很多时间。

#5


6  

Another reason that user controls may not show up in the toolbox is if they do not have a default constructor.

用户控件可能不会出现在工具箱中的另一个原因是它们没有默认的构造函数。

#6


5  

Also double check that your user controls have a valid Namespace.

还要再次检查您的用户控件是否有一个有效的名称空间。

I just found that controls without namespace are not placed inside the ToolBox.

我刚刚发现没有命名空间的控件没有放在工具箱中。

#7


4  

Usually you need to build the solution. That almost always works for me.

通常需要构建解决方案。几乎总是对我有用。

#8


3  

I had the same problem. After a lot of googling I did not find anything, but by chance I found out that if you click on the toolbox while you are in the same project that you have created the user control in, and check "show all", then a group with the same name as your project will appear at the top of toolbox which you can find your user control in. Now you can add your control on your desired form!

我也有同样的问题。很多搜索之后,我没有发现任何东西,但是偶然的机会我发现如果你单击工具箱在同一个项目时,您已经创建了用户控制,并检查“显示所有”,然后一群具有相同名称作为项目将出现在顶部的工具箱,您可以找到您的用户控制。现在您可以将您的控件添加到所需的窗体上!

#9


3  

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.

对于使用ToolStripItems(例如ToolStripStatusLabel)的人来说,要让派生控件显示在下拉菜单中(比如StatusStrip的那个),您需要将类设置为public,然后构建解决方案。

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

也不要忘记类的designer属性,类似如下:

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.

我花了一段时间才把它弄对。希望这能节省别人的时间。

#10


3  

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.

右键单击工具箱中的某个地方并单击“选择项目”。当我找到我的物品时,它已经被检查过了。然后我选中这个项目,点击ok。接下来,我再次右击工具箱,搜索我的项目……它消失了,所以我单击Browse,导航到obj/x86/debug文件夹,并选择了exe。然后将项目正确地添加到工具箱中。

I think it's a VS bug.

我认为这是一个VS错误。

#11


3  

Apart all instructions that have been given(Tools > Options > Windows Forms Designer > General : AutoToolboxPopulate) + you need to build the solution (which is obvious for me) you will probably have to pay attention to the class access modifier: it MUST be PUBLIC. I just created a control and did not appeared in toolbox list and I did not knew why. So after set

除了已经给出的所有指令(工具>选项> Windows窗体设计器>通用:AutoToolboxPopulate) +您需要构建解决方案(对我来说很明显),您可能需要注意类访问修饰符:它必须是公共的。我刚刚创建了一个控件,没有出现在工具箱列表中,我不知道为什么。所以在设置

public class  yourClass:control {}

than it appeared in list. ;) Hope this will help others.

比列在清单上的要多。,)希望这能帮助别人。

#12


2  

Check your build output directory. If for some reason you are building your output somewhere other than the project bin\ directory, your controls won't show up in your toolbox.

检查构建输出目录。如果由于某种原因,您正在构建的输出不是项目bin\目录,那么您的控件将不会出现在工具箱中。

#13


2  

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 :).

我的问题是:我为我的控件添加了一个新的构造函数,它接受了一些参数,但是我没有显式地重新声明空的构造函数!工具箱只能包含具有空构造函数的控件。通常,在vb中设计类时,它有一个隐式定义的空构造函数(意味着不需要声明一个)。但是,一旦您开始设计自己的构造函数,这个空的构造函数就会消失,所以您需要在代码中显式地重新定义它!无论如何,我意识到大多数经验丰富的vb程序员已经知道了这一切,但希望这能帮助像我一样的新手:)。

#14


1  

It is possible for all of the above to fail.

以上这些都有可能失败。

I fixed it by creating a new user control (TestControl) and it triggered Visual Studio to magically add my project's controls tab + controls back into the Toolbox. Then I just deleted the test control.

我通过创建一个新的用户控件(TestControl)来修复它,它触发了Visual Studio,可以神奇地将项目的controls +控件添加回工具箱。然后我删除了测试控件。

This happened to me after recently installing a VS 2008 automated windows update, by the way.

顺便说一句,在最近安装了VS 2008自动windows更新之后,我就遇到了这种情况。

#15


1  

What I usually do is create a new tab and add the exe/dll to that tab... Not too comfortable with that solution because of the load time and general hassle.

我通常做的是创建一个新的标签,并添加exe/dll到那个标签…由于负载时间和一般的麻烦,对这种解决方案不太满意。

A friend showed me a way to speed this up. Instead of having to click "Choose Items..." in the toolbox,etc, for each new control you make - You can create a file named MyCustomControls and there you can create your custom controls.

一个朋友给我展示了加速的方法。你可以创建一个名为MyCustomControls的文件,在那里你可以创建你的自定义控件。

Now you only have to do the "Choose Items..." and add this file ONCE. If you later on decide to add a new control, create it in MyCustomControls and then rebuild.
Then your toolbox will have your new control. (It will be displayed automatically with a regular compile if you have AutoToolboxPopulate I think)

现在您只需执行“选择项…”,并添加此文件一次。如果您稍后决定添加一个新控件,请在MyCustomControls中创建它,然后重新构建。然后你的工具箱将有你的新控件。(我认为,如果你有AutoToolboxPopulate,它会自动显示,并定期编译)

This is unfortunate, because often you want to separate classes into "one class per file". It is horrible that you have to ruin your code architecture just because VS doesn't want to do it your way. :)

这是不幸的,因为您通常希望将类划分为“每个文件一个类”。很可怕的是,你必须破坏你的代码架构,仅仅因为VS不想按照你的方式去做。:)

I am not too comfortable with this solution either but if you need to do something quick and you don't care about multiple user controls within a file or just are lazy, this might suit you well. :)

我对这个解决方案也不是很满意,但是如果您需要做一些快速的事情,并且您不关心文件中的多个用户控件,或者只是懒惰,这可能非常适合您。:)

#16


1  

Well, nothing was working for me except this worked...

对我来说,没有什么是有用的,除了这个有用……

  1. I create a new project in my solution, and for this project it works so I was going to start using this one
  2. 我在我的解决方案中创建了一个新项目,对于这个项目,它起作用了,所以我将开始使用这个
  3. Playing arond, I started tweaking the xml of the csproj file to find out what was wrong with my other project in the same solution and then I reset it as it didn't seem to be working
  4. 扮演arond之后,我开始对csproj文件的xml进行调整,以找出同一解决方案中我的另一个项目有什么问题,然后重新设置它,因为它似乎不工作
  5. It is now magically working again in my project
  6. 现在它又神奇地在我的项目中工作了

Not a very good solution but you should try these steps

这不是一个很好的解决方案,但是您应该尝试以下步骤

  1. See if it works in a brand new solution/project.
  2. 看看它是否适用于一个全新的解决方案/项目。
  3. See if it works in a brand new project in the same solution
  4. 看看它是否在同一解决方案中的一个全新项目中有效。
  5. If #2 worked, maybe compare .csproj files...somehow mine started working again while I was doing this(this is very frustrating).
  6. 如果#2有效,可以比较。csproj文件…在我做这个的时候,我的工作又开始了(这是非常令人沮丧的)。

#17


1  

Providing you already tried tinkering with:

如果你已经试过修修补补:

  • Tools > Options > Windows Forms Designer > General : AutoToolboxPopulate
  • 工具>选项> Windows窗体设计器>通用:autotoolbox填充
  • Tools > Options > Text Editor > XMAL > Misc : AutoToolboxPopulate
  • >选项>文本编辑> XMAL > Misc: AutoToolboxPopulate。
  • created a default constructor
  • 创建一个默认的构造函数
  • build your project / reset the toolbox and add manually your tab
  • 构建您的项目/重置工具箱并手动添加您的选项卡。

Yet you still see it greyed out..

然而你仍然看到它变灰了。

Check your path length and check the charcters being used in your absolute path.

检查路径长度并检查绝对路径中使用的图表。

I had a project residing in "C:\Users\myName\myCompany\R&D\Projects"
And after few hours found out that the "R&D" is the problem..
The '&' did not allow my usercontrol items to be enabled in my toolbox.

我有一个项目位于“C:\用户名称\myName公司\研发项目”,几个小时后发现“研发”是问题所在。“&”不允许在工具箱中启用usercontrol项。

#18


1  

I fell into this trap just a couple of hours ago.
I've got a .NET 2.0 Windows Application project with some custom UserControls; it worked fine. So I decided to order my files in subfolders, to make my project a little bit cleaner.
After that, Visual Studio 2010 designer stopped loading my forms, and ToolBox won't show my controls anymore.
I freaked out, moving back source files in project root, resetting ToolBox, but nothing seemed to work. After that, I remembered I used ReSharper "Remove Unused References", so I tried to put back unused reference, in particular System.Data: problem solved! :O I can't say you why, but this worked for me.
Hope my experience can help someone else. :)
Bye, Nando

我几个小时前掉进了这个陷阱。我有一个。net 2.0 Windows应用程序项目,有一些自定义用户控件;它工作得很好。所以我决定把我的文件放在子文件夹里,这样我的项目就会更简洁一些。之后,Visual Studio 2010 designer停止加载我的表单,工具箱将不再显示我的控件。我吓坏了,在project root中移动源文件,重新设置工具箱,但似乎什么都不管用。在那之后,我记得我使用了ReSharper“删除未使用的引用”,所以我尝试把未使用的引用放回原处,特别是系统。数据:问题解决了!我不能说为什么,但这对我很有效。希望我的经验能对别人有所帮助。:Nando)再见

#19


1  

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.

如果您仍然无法找到为什么您的vstudio工具箱没有使用您的usercontrols填充。然后可以使用另一个visual studio调试vstudio。你可以在这里找到。

#20


1  

If you've tried following all the other answers and it still doesn't work, the following fixed it for me:

如果你试着按照所有其他的答案去做,但还是没有成功,下面为我修正:

  • Right click on your project containing your control.
  • 右键单击包含控件的项目。
  • Select Properties.
  • 选择Properties。
  • In the Build settings category, make sure Register for COM interop is checked.
  • 在Build settings类别中,确保选中了COM interop的Register。

#21


1  

In my case the reason of error was an excess length of a path to my control's .dll. I had shrunk it a bit and everything became working fine.

在我的例子中,错误的原因是路径的长度超过了控件的.dll。我把它缩了一点,一切都好了。

Also I found out that the special symbols (e.g. I used #) in a path affect a control display.

我还发现,在路径中特殊的符号(例如,我使用#)会影响控制显示。

Hope it solves the issue.

希望它能解决这个问题。

#22


0  

In your UserControl, make sure that New is declared Public. It won't show up if it's just declared Sub New (which defaults to Friend).

在您的UserControl中,确保New是公开的。如果只是声明为Sub New(默认为Friend),它就不会出现。

#23


0  

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

症状1:表单、UserControl和组件的设计视图失败!

  • My Form design view was failing w/ the msg "can not find 'User Control'."
  • 我的表单设计视图失败了w/ msg“找不到‘用户控制’”。
  • If I could get the Form design view to work it was very unstable & corrupted all to hell w/ any change.
  • 如果我能得到表单设计视图的工作,它就非常不稳定,并且被破坏到地狱w/任何变化。

Symptom 2: The UserControl & Component in the Toolbox

症状2:工具箱中的UserControl和组件

  • 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

解决方案:在vb中设置UserControl和组件后的范围为Public

#24


0  

Check project path, avoid & , # etc.

检查项目路径,避免&,#等。

I've moved my solution from drive:\work\c#\folder\ to drive:\work\folder and it solved the problem.

我已经把我的解决方案从驱动器:\工作\c#\文件夹到驱动器:\工作\文件夹,它解决了问题。

#25


0  

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

我正在尝试只构建一个x64应用程序,因此我的平台目标当然被设置为x64。

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.

然而,即使在2016年,Visual Studio (devenv.exe)仍然是一个32位的进程,并且它不能加载64位的程序集。为了检查您的Visual Studio的bitness,打开任务管理器,并在进程的名称中检查*32。

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.

查找工具箱中的控件:将平台目标设置为项目设置中的任何CPU。如果需要的话,对调试和发布构建执行此操作。

#26


0  

When I tried to add my UserControl to the toolbox (right click toolbox, choose items, select my DLL) it would display a message saying there were no controls in my DLL.

当我尝试将UserControl添加到工具箱(右键单击工具箱,选择项,选择我的DLL)时,它会显示一条消息,说我的DLL中没有控件。

Anyway, the problem was solved, by trying to create a form in my DLL in VS and adding the UserControl. An error message displayed saying there was no default constructor

无论如何,问题已经解决了,通过尝试在VS中创建一个DLL中的表单并添加UserControl。显示一个错误消息,说没有默认的构造函数

public UserControl() {
...
}

The designer needs this because it can't know what valid arguments are. Once I added a blank constructor to the UserControl it was added to the toolbox without issue.

设计者需要它,因为它不知道什么是有效的参数。一旦我向UserControl添加了一个空白的构造函数,它就会被添加到工具箱中。

#27


0  

As mentioned here you should tell the visual studio to load your usercontrol in toolbox.

正如这里提到的,您应该告诉visual studio在工具箱中加载您的usercontrol。

[ToolboxItem(true)]
public class PanelTitle : LabelControl  {
// Whatever code to override LabelControl here...
}

#28


0  

Before trying to add a custom control, make sure that it is compatible with the .Net version of your current project.

在尝试添加自定义控件之前,请确保它与当前项目的。net版本兼容。

I was trying to add a custom control to toolbox for a project for Windows CE 5.0 and .Net Compact v3.5 on VS2008. I did all those previous suggestions but nothing worked. The control shows up when "show all" is checked but it is grayed , even in "Choose Items" menu is checked.

我试图在VS2008上为Windows CE 5.0和。net Compact v3.5的项目添加一个自定义控件。我做了所有那些之前的建议,但没有任何效果。控件在“show all”被选中时显示,但它是灰色的,甚至在“Choose Items”菜单中也被选中。

I created a new project with .Net v2.0 and it worked perfectly.

我用。net v2.0创建了一个新项目,它运行得非常好。

#29


-1  

hello its answer Ctrl+Alt+X take this and later u have TOOLBOX :)

你好,它的答案是Ctrl+Alt+X取这个,然后你有工具箱:)

#1


80  

Check this setting:

检查这个设置:

Tools > Options > Windows Forms Designer > General : AutoToolboxPopulate

工具>选项> Windows窗体设计器>通用:autotoolbox填充

It should be set to True for this to work.

它应该被设置为正确的工作。

#2


29  

  1. Build your project to make sure it compiles.

    构建您的项目以确保它编译。

  2. With the form that you want your user control on, open the toolbox, right click and select "choose items"

    使用您希望用户控件打开的表单,打开工具箱,右键单击并选择“选择项”

  3. Browse to your .exe or dll that you compiled in step 1.

    浏览到您在步骤1中编译的.exe或dll。

  4. make sure that your user control has a tick next to it, press OK.

    确保您的用户控件旁边有一个勾号,按下OK。

  5. Your user control should appear in the toolbox, so drag it onto your form.

    您的用户控件应该出现在工具箱中,因此将它拖到窗体上。

This is adapted from Calanus's answer to a similar question.

这是根据Calanus对类似问题的回答。

#3


18  

In my case, the AutoToolboxPopulate was already set (Visual C# 2010 Express).

在我的例子中,AutoToolboxPopulate已经设置好了(Visual c# 2010 Express)。

However, I had to activate "Show All" from the properties of the Toolbox (right click) to actually see my new user controls.

但是,我必须从工具箱(右击)的属性中激活“显示全部”,以实际看到我的新用户控件。

#4


11  

Up until now, I had no problem with usercontrols not showing in the toolbox. Build the project and it just shows up. Then today not working. After a search I went through following but still no joy.

到目前为止,我对没有显示在工具箱中的用户控件没有问题。构建项目,它就会出现。然后今天不工作。搜寻之后,我继续追寻,但仍然没有快乐。

  • Tools > Options > Windows Forms Designer > General : AutoToolboxPopulate
  • 工具>选项> Windows窗体设计器>通用:autotoolbox填充
  • Tools > Options > Text Editor > XMAL > Misc : AutoToolboxPopulate
  • >选项>文本编辑> XMAL > Misc: AutoToolboxPopulate。
  • Reset the VS settings to default
  • 将VS设置重置为默认设置

So after a few hours of messing around trying to get it to work with no success, I created a new WPF windows project accepting the default name and added a usercontrol. Built the project and the user control appeared as it always had.

因此,在花了几个小时试图让它工作并没有成功之后,我创建了一个新的WPF windows项目,接受默认名称并添加了一个usercontrol。构建了项目,用户控件一如既往地出现。

I then thought that something might be wrong with my project or wpf window file. Removed the project, created a new one and added a new control. Built the project but it didnt work.

然后我认为我的项目或wpf窗口文件可能有问题。删除项目,创建一个新项目,并添加一个新控件。建造了这个项目,但没有成功。

The only thing I did different was choose a name for the project, which I included a space in the name "WPF Application".

我做的唯一不同的事情是为项目选择一个名称,其中包括一个名为“WPF应用程序”的空间。

Removed the project again and created a new one again called "WPFApplication" without the space and added a user control. Built it and the user control showed up.

再次删除该项目,并创建了一个新的名为“WPFApplication”的项目,并添加了一个用户控件。构建后,出现了用户控件。

If you want usercontrols to show up automatically in the toolbox on build, dont use spaces in the project name. Hopefully this post save's someone else a ton of wasted time.

如果您希望用户控件在build上的工具箱中自动显示,请不要在项目名称中使用空格。希望这篇文章能让别人省下很多时间。

#5


6  

Another reason that user controls may not show up in the toolbox is if they do not have a default constructor.

用户控件可能不会出现在工具箱中的另一个原因是它们没有默认的构造函数。

#6


5  

Also double check that your user controls have a valid Namespace.

还要再次检查您的用户控件是否有一个有效的名称空间。

I just found that controls without namespace are not placed inside the ToolBox.

我刚刚发现没有命名空间的控件没有放在工具箱中。

#7


4  

Usually you need to build the solution. That almost always works for me.

通常需要构建解决方案。几乎总是对我有用。

#8


3  

I had the same problem. After a lot of googling I did not find anything, but by chance I found out that if you click on the toolbox while you are in the same project that you have created the user control in, and check "show all", then a group with the same name as your project will appear at the top of toolbox which you can find your user control in. Now you can add your control on your desired form!

我也有同样的问题。很多搜索之后,我没有发现任何东西,但是偶然的机会我发现如果你单击工具箱在同一个项目时,您已经创建了用户控制,并检查“显示所有”,然后一群具有相同名称作为项目将出现在顶部的工具箱,您可以找到您的用户控制。现在您可以将您的控件添加到所需的窗体上!

#9


3  

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.

对于使用ToolStripItems(例如ToolStripStatusLabel)的人来说,要让派生控件显示在下拉菜单中(比如StatusStrip的那个),您需要将类设置为public,然后构建解决方案。

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

也不要忘记类的designer属性,类似如下:

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.

我花了一段时间才把它弄对。希望这能节省别人的时间。

#10


3  

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.

右键单击工具箱中的某个地方并单击“选择项目”。当我找到我的物品时,它已经被检查过了。然后我选中这个项目,点击ok。接下来,我再次右击工具箱,搜索我的项目……它消失了,所以我单击Browse,导航到obj/x86/debug文件夹,并选择了exe。然后将项目正确地添加到工具箱中。

I think it's a VS bug.

我认为这是一个VS错误。

#11


3  

Apart all instructions that have been given(Tools > Options > Windows Forms Designer > General : AutoToolboxPopulate) + you need to build the solution (which is obvious for me) you will probably have to pay attention to the class access modifier: it MUST be PUBLIC. I just created a control and did not appeared in toolbox list and I did not knew why. So after set

除了已经给出的所有指令(工具>选项> Windows窗体设计器>通用:AutoToolboxPopulate) +您需要构建解决方案(对我来说很明显),您可能需要注意类访问修饰符:它必须是公共的。我刚刚创建了一个控件,没有出现在工具箱列表中,我不知道为什么。所以在设置

public class  yourClass:control {}

than it appeared in list. ;) Hope this will help others.

比列在清单上的要多。,)希望这能帮助别人。

#12


2  

Check your build output directory. If for some reason you are building your output somewhere other than the project bin\ directory, your controls won't show up in your toolbox.

检查构建输出目录。如果由于某种原因,您正在构建的输出不是项目bin\目录,那么您的控件将不会出现在工具箱中。

#13


2  

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 :).

我的问题是:我为我的控件添加了一个新的构造函数,它接受了一些参数,但是我没有显式地重新声明空的构造函数!工具箱只能包含具有空构造函数的控件。通常,在vb中设计类时,它有一个隐式定义的空构造函数(意味着不需要声明一个)。但是,一旦您开始设计自己的构造函数,这个空的构造函数就会消失,所以您需要在代码中显式地重新定义它!无论如何,我意识到大多数经验丰富的vb程序员已经知道了这一切,但希望这能帮助像我一样的新手:)。

#14


1  

It is possible for all of the above to fail.

以上这些都有可能失败。

I fixed it by creating a new user control (TestControl) and it triggered Visual Studio to magically add my project's controls tab + controls back into the Toolbox. Then I just deleted the test control.

我通过创建一个新的用户控件(TestControl)来修复它,它触发了Visual Studio,可以神奇地将项目的controls +控件添加回工具箱。然后我删除了测试控件。

This happened to me after recently installing a VS 2008 automated windows update, by the way.

顺便说一句,在最近安装了VS 2008自动windows更新之后,我就遇到了这种情况。

#15


1  

What I usually do is create a new tab and add the exe/dll to that tab... Not too comfortable with that solution because of the load time and general hassle.

我通常做的是创建一个新的标签,并添加exe/dll到那个标签…由于负载时间和一般的麻烦,对这种解决方案不太满意。

A friend showed me a way to speed this up. Instead of having to click "Choose Items..." in the toolbox,etc, for each new control you make - You can create a file named MyCustomControls and there you can create your custom controls.

一个朋友给我展示了加速的方法。你可以创建一个名为MyCustomControls的文件,在那里你可以创建你的自定义控件。

Now you only have to do the "Choose Items..." and add this file ONCE. If you later on decide to add a new control, create it in MyCustomControls and then rebuild.
Then your toolbox will have your new control. (It will be displayed automatically with a regular compile if you have AutoToolboxPopulate I think)

现在您只需执行“选择项…”,并添加此文件一次。如果您稍后决定添加一个新控件,请在MyCustomControls中创建它,然后重新构建。然后你的工具箱将有你的新控件。(我认为,如果你有AutoToolboxPopulate,它会自动显示,并定期编译)

This is unfortunate, because often you want to separate classes into "one class per file". It is horrible that you have to ruin your code architecture just because VS doesn't want to do it your way. :)

这是不幸的,因为您通常希望将类划分为“每个文件一个类”。很可怕的是,你必须破坏你的代码架构,仅仅因为VS不想按照你的方式去做。:)

I am not too comfortable with this solution either but if you need to do something quick and you don't care about multiple user controls within a file or just are lazy, this might suit you well. :)

我对这个解决方案也不是很满意,但是如果您需要做一些快速的事情,并且您不关心文件中的多个用户控件,或者只是懒惰,这可能非常适合您。:)

#16


1  

Well, nothing was working for me except this worked...

对我来说,没有什么是有用的,除了这个有用……

  1. I create a new project in my solution, and for this project it works so I was going to start using this one
  2. 我在我的解决方案中创建了一个新项目,对于这个项目,它起作用了,所以我将开始使用这个
  3. Playing arond, I started tweaking the xml of the csproj file to find out what was wrong with my other project in the same solution and then I reset it as it didn't seem to be working
  4. 扮演arond之后,我开始对csproj文件的xml进行调整,以找出同一解决方案中我的另一个项目有什么问题,然后重新设置它,因为它似乎不工作
  5. It is now magically working again in my project
  6. 现在它又神奇地在我的项目中工作了

Not a very good solution but you should try these steps

这不是一个很好的解决方案,但是您应该尝试以下步骤

  1. See if it works in a brand new solution/project.
  2. 看看它是否适用于一个全新的解决方案/项目。
  3. See if it works in a brand new project in the same solution
  4. 看看它是否在同一解决方案中的一个全新项目中有效。
  5. If #2 worked, maybe compare .csproj files...somehow mine started working again while I was doing this(this is very frustrating).
  6. 如果#2有效,可以比较。csproj文件…在我做这个的时候,我的工作又开始了(这是非常令人沮丧的)。

#17


1  

Providing you already tried tinkering with:

如果你已经试过修修补补:

  • Tools > Options > Windows Forms Designer > General : AutoToolboxPopulate
  • 工具>选项> Windows窗体设计器>通用:autotoolbox填充
  • Tools > Options > Text Editor > XMAL > Misc : AutoToolboxPopulate
  • >选项>文本编辑> XMAL > Misc: AutoToolboxPopulate。
  • created a default constructor
  • 创建一个默认的构造函数
  • build your project / reset the toolbox and add manually your tab
  • 构建您的项目/重置工具箱并手动添加您的选项卡。

Yet you still see it greyed out..

然而你仍然看到它变灰了。

Check your path length and check the charcters being used in your absolute path.

检查路径长度并检查绝对路径中使用的图表。

I had a project residing in "C:\Users\myName\myCompany\R&D\Projects"
And after few hours found out that the "R&D" is the problem..
The '&' did not allow my usercontrol items to be enabled in my toolbox.

我有一个项目位于“C:\用户名称\myName公司\研发项目”,几个小时后发现“研发”是问题所在。“&”不允许在工具箱中启用usercontrol项。

#18


1  

I fell into this trap just a couple of hours ago.
I've got a .NET 2.0 Windows Application project with some custom UserControls; it worked fine. So I decided to order my files in subfolders, to make my project a little bit cleaner.
After that, Visual Studio 2010 designer stopped loading my forms, and ToolBox won't show my controls anymore.
I freaked out, moving back source files in project root, resetting ToolBox, but nothing seemed to work. After that, I remembered I used ReSharper "Remove Unused References", so I tried to put back unused reference, in particular System.Data: problem solved! :O I can't say you why, but this worked for me.
Hope my experience can help someone else. :)
Bye, Nando

我几个小时前掉进了这个陷阱。我有一个。net 2.0 Windows应用程序项目,有一些自定义用户控件;它工作得很好。所以我决定把我的文件放在子文件夹里,这样我的项目就会更简洁一些。之后,Visual Studio 2010 designer停止加载我的表单,工具箱将不再显示我的控件。我吓坏了,在project root中移动源文件,重新设置工具箱,但似乎什么都不管用。在那之后,我记得我使用了ReSharper“删除未使用的引用”,所以我尝试把未使用的引用放回原处,特别是系统。数据:问题解决了!我不能说为什么,但这对我很有效。希望我的经验能对别人有所帮助。:Nando)再见

#19


1  

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.

如果您仍然无法找到为什么您的vstudio工具箱没有使用您的usercontrols填充。然后可以使用另一个visual studio调试vstudio。你可以在这里找到。

#20


1  

If you've tried following all the other answers and it still doesn't work, the following fixed it for me:

如果你试着按照所有其他的答案去做,但还是没有成功,下面为我修正:

  • Right click on your project containing your control.
  • 右键单击包含控件的项目。
  • Select Properties.
  • 选择Properties。
  • In the Build settings category, make sure Register for COM interop is checked.
  • 在Build settings类别中,确保选中了COM interop的Register。

#21


1  

In my case the reason of error was an excess length of a path to my control's .dll. I had shrunk it a bit and everything became working fine.

在我的例子中,错误的原因是路径的长度超过了控件的.dll。我把它缩了一点,一切都好了。

Also I found out that the special symbols (e.g. I used #) in a path affect a control display.

我还发现,在路径中特殊的符号(例如,我使用#)会影响控制显示。

Hope it solves the issue.

希望它能解决这个问题。

#22


0  

In your UserControl, make sure that New is declared Public. It won't show up if it's just declared Sub New (which defaults to Friend).

在您的UserControl中,确保New是公开的。如果只是声明为Sub New(默认为Friend),它就不会出现。

#23


0  

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

症状1:表单、UserControl和组件的设计视图失败!

  • My Form design view was failing w/ the msg "can not find 'User Control'."
  • 我的表单设计视图失败了w/ msg“找不到‘用户控制’”。
  • If I could get the Form design view to work it was very unstable & corrupted all to hell w/ any change.
  • 如果我能得到表单设计视图的工作,它就非常不稳定,并且被破坏到地狱w/任何变化。

Symptom 2: The UserControl & Component in the Toolbox

症状2:工具箱中的UserControl和组件

  • 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

解决方案:在vb中设置UserControl和组件后的范围为Public

#24


0  

Check project path, avoid & , # etc.

检查项目路径,避免&,#等。

I've moved my solution from drive:\work\c#\folder\ to drive:\work\folder and it solved the problem.

我已经把我的解决方案从驱动器:\工作\c#\文件夹到驱动器:\工作\文件夹,它解决了问题。

#25


0  

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

我正在尝试只构建一个x64应用程序,因此我的平台目标当然被设置为x64。

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.

然而,即使在2016年,Visual Studio (devenv.exe)仍然是一个32位的进程,并且它不能加载64位的程序集。为了检查您的Visual Studio的bitness,打开任务管理器,并在进程的名称中检查*32。

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.

查找工具箱中的控件:将平台目标设置为项目设置中的任何CPU。如果需要的话,对调试和发布构建执行此操作。

#26


0  

When I tried to add my UserControl to the toolbox (right click toolbox, choose items, select my DLL) it would display a message saying there were no controls in my DLL.

当我尝试将UserControl添加到工具箱(右键单击工具箱,选择项,选择我的DLL)时,它会显示一条消息,说我的DLL中没有控件。

Anyway, the problem was solved, by trying to create a form in my DLL in VS and adding the UserControl. An error message displayed saying there was no default constructor

无论如何,问题已经解决了,通过尝试在VS中创建一个DLL中的表单并添加UserControl。显示一个错误消息,说没有默认的构造函数

public UserControl() {
...
}

The designer needs this because it can't know what valid arguments are. Once I added a blank constructor to the UserControl it was added to the toolbox without issue.

设计者需要它,因为它不知道什么是有效的参数。一旦我向UserControl添加了一个空白的构造函数,它就会被添加到工具箱中。

#27


0  

As mentioned here you should tell the visual studio to load your usercontrol in toolbox.

正如这里提到的,您应该告诉visual studio在工具箱中加载您的usercontrol。

[ToolboxItem(true)]
public class PanelTitle : LabelControl  {
// Whatever code to override LabelControl here...
}

#28


0  

Before trying to add a custom control, make sure that it is compatible with the .Net version of your current project.

在尝试添加自定义控件之前,请确保它与当前项目的。net版本兼容。

I was trying to add a custom control to toolbox for a project for Windows CE 5.0 and .Net Compact v3.5 on VS2008. I did all those previous suggestions but nothing worked. The control shows up when "show all" is checked but it is grayed , even in "Choose Items" menu is checked.

我试图在VS2008上为Windows CE 5.0和。net Compact v3.5的项目添加一个自定义控件。我做了所有那些之前的建议,但没有任何效果。控件在“show all”被选中时显示,但它是灰色的,甚至在“Choose Items”菜单中也被选中。

I created a new project with .Net v2.0 and it worked perfectly.

我用。net v2.0创建了一个新项目,它运行得非常好。

#29


-1  

hello its answer Ctrl+Alt+X take this and later u have TOOLBOX :)

你好,它的答案是Ctrl+Alt+X取这个,然后你有工具箱:)