问题
I want to add my custom control into the VS Toolbox. But I need it to appear in toolbox always when a new project is open. How can I do that?
回答1:
Create a VSIX package to install the control
You can create a VSIX package to distribute and install user controls to toolbox.
To do so, you can create a VSIX Project and add a Windows Forms ToolBox Control to the project. The control is decorated with a ProvideToolboxControl
attribute which determines the tab that the control will appear in. You can pass an existing or a new tab name to the attribute:
[ProvideToolboxControl("Some Tab Name", false)]
public partial class ToolboxControl1 : UserControl
You can also fill the information in .vsixmanifest
file. Then when you build the project, it creates a .vsix
package file in \bin\debug
folder of the project which you can distribute this file. If you run the file, it installs the control in visual studio toolbox.
More information:
- Walkthrough: Creating a Windows Forms Toolbox Control
Note:
- VS 2013 has a Windows Forms ToolBox Control Project Template under extensibility group of new project window and you can use it to create the project. Starting from VS 2015 you should use VSIX Project template.
Manually Add Control to Toolbox
You can copy the dll of your control to a permanent location. Then right click on ToolBox, for example on general tab, then click Choose Items ...
then in Choose Toolbox Items window in .Net Framework Components
Tab, click Browse...
button and open the dll of your control. Then in the components list, check the control and click OK
button. The control will appear under the selected tab. You also can add your own tab simply by right click and choose Add Tab
.
来源:https://stackoverflow.com/questions/36097875/how-to-add-a-custom-windows-forms-control-into-visual-studio-toolbox