How to add a Custom Windows Forms Control into Visual Studio Toolbox

孤街浪徒 提交于 2019-12-28 07:05:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!