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?
As mentioned here you should tell the visual studio to load your usercontrol in toolbox.
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.
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
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.
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.
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.
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.
The only thing I did different was choose a name for the project, which I included a space in the name "WPF Application".
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.
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.
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
than it appeared in list. ;) Hope this will help others.
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.
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.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)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. :)
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. :)
Well, nothing was working for me except this worked...
Not a very good solution but you should try these steps