如何将自定义Windows窗体控件添加到Visual Studio工具箱 [英] How to add a Custom Windows Forms Control into Visual Studio Toolbox

查看:627
本文介绍了如何将自定义Windows窗体控件添加到Visual Studio工具箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将自定义控件添加到VS 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?

推荐答案

创建VSIX软件包以安装控件

您可以创建一个 VSIX 包,以将用户控件分发并安装到工具箱。

You can create a VSIX package to distribute and install user controls to toolbox.

为此,您可以创建一个 VSIX项目,然后向该项目中添加一个 Windows窗体工具箱控件。控件装饰有 ProvideToolboxControl 属性,该属性确定控件将出现在其中的选项卡。您可以将现有或新的选项卡名称传递给该属性:

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

您也可以在 .vsixmanifest 文件中填写信息。然后,在构建项目时,它将在> bin\debug 文件夹的 .vsix 包文件中创建一个您可以分发此文件的项目。如果运行该文件,它将在Visual Studio工具箱中安装该控件。

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.

更多信息:

  • Walkthrough: Creating a Windows Forms Toolbox Control

注意:


  • VS 2013在新项目窗口的可扩展性组下有一个 Windows窗体工具箱控件项目模板,您可以使用它来创建项目。从VS 2015开始,您应该使用 VSIX Project 模板。

  • 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.

手动将控件添加到工具箱

您可以将控件的dll复制到永久位置。然后右键单击工具箱,例如在常规选项卡上,然后单击 选择项目... ,然后在 .Net Framework Components <的选择工具箱项窗口中。 / code>标签,单击浏览... 按钮,然后打开控件的dll。然后在组件列表中,检查控件,然后单击确定按钮。该控件将出现在所选选项卡下。您还可以通过右键单击并选择添加标签来添加自己的标签。

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.

这篇关于如何将自定义Windows窗体控件添加到Visual Studio工具箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆