Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
679 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 indebug 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:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...