I made a usercontrol in my project, and after building project, I need to put it in my toolbox, and use it as a common control. but i can\'t. the UserControl
is
Basic qustion if you are using generics in your base control. If yes:
lets say we have control:
public class MyComboDropDown : ComboDropDownComon<MyType>
{
public MyComboDropDown() { }
}
MyComboDropDown will not allow to open designer on it and will be not shown in Toolbox. Why? Because base control is not already compiled - when MyComboDropDown is complied. You can modify to this:
public class MyComboDropDown : MyComboDropDownBase
{
public MyComboDropDown() { }
}
public class MyComboDropDownBase : ComboDropDownComon<MyType>
{
}
Than after rebuild, and reset toolbox it should be able to see MyComboDropDown in designer and also in Toolbox
Right-click on toolbar then click on "choose item" in context menu. A dialog with registered components pops up. in this dialog click "Browse" to select your assembly with the usercontrol you want to use.
PS. This assembly should be registered before.
I found that the user control must have a parameterless constructor or it won't show up in the list. at least that was true in vs2005.
I'm assuming you're using VS2010 (that's what you've tagged the question as) I had problems getting them to add automatically to the toolbox as in VS2008/2005. There's actually an option to stop the toolbox auto populating!
Go to Tools > Options > Windows Forms Designer > General
At the bottom of the list you'll find Toolbox > AutoToolboxPopulate which on a fresh install defaults to False. Set it true and then rebuild your solution.
Hey presto they user controls in you solution should be automatically added to the toolbox. You might have to reload the solution as well.
Recompiling did the trick for me!
Using VS 2010:
Let's say you have a Windows.Forms project. You add a UserControl (say MyControl) to the project, and design it all up. Now you want to add it to your toolbox.
As soon as the project is successfully built once, it will appear in your Framework Components. Right click the Toolbox to get the context menu, select "Choose Items...", and browse to the name of your control (MyControl) under the ".NET Framework Components" tab.
Advantage over using dlls: you can edit the controls in the same project as your form, and the form will build with the new controls. However, the control will only be avilable to this project.
Note: If the control has build errors, resolve them before moving on to the containing forms, or the designer has a heart attack.