如何将我的新用户控件添加到工具箱或新的 Winform?

How do I add my new User Control to the Toolbox or a new Winform?(如何将我的新用户控件添加到工具箱或新的 Winform?)

本文介绍了如何将我的新用户控件添加到工具箱或新的 Winform?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的库(不是 Winforms 应用程序),它为真正的 Windows 应用程序提供一些 Winforms.在这个库中,我想创建一个用户控件来将一些控件组合在一起.为此,我右键单击、添加、用户控件并将一些控件拖到新的用户控件上.

I have an existing library (not a Winforms application) that supplies some Winforms to a bona-fide Windows application. Within this library, I would like to create a User Control to group some controls together. To accomplish this, I right-clicked, Add, User Control and dragged some controls onto the new User Control.

到目前为止,一切都很好.用户控制甚至有必要的用户控制图标.但是将新的用户控件从解决方案资源管理器拖到一个新的空白 Winform 不起作用(我得到一个带有一条线的圆圈),并将它拖到工具箱也不起作用(即使我得到一个 + 号当我将它拖到工具箱上时).

So far, so good. The User Control even has the requisite User Control icon. But dragging the new User Control from the Solution Explorer to a new blank Winform does not work (I get a circle with a line through it), and dragging it over to the Toolbox doesn't work either (even though I get a + sign when I drag it over the Toolbox).

是否有某种 XML 魔法或其他我缺少的东西来完成这项工作?

Is there some sort of XML magic or something else I'm missing to make this work?

注意:我在使用 Visual Studio 2008 时遇到了一些问题,我通过遵循 这里.现在,我只需重新构建项目,就可以将添加到现有项目中的用户控件放入工具箱中.

Note: I had some problems with Visual Studio 2008 that I managed to fix by following the workarounds that can be found here. I am now able to get User Controls I added to my existing project into the toolbox by simply rebuilding the project.

推荐答案

假设我明白你的意思:

  1. 如果您的 UserControl 在库中,您可以使用

  1. If your UserControl is in a library you can add this to you Toolbox using

工具箱 -> 右键 -> 选择项目 -> 浏览

Toolbox -> right click -> Choose Items -> Browse

使用 UserControl 选择您的程序集.

Select your assembly with the UserControl.

如果 UserControl 是您项目的一部分,您只需构建整个解决方案.之后,您的 UserControl 应该会出现在工具箱中.

If the UserControl is part of your project you only need to build the entire solution. After that, your UserControl should appear in the toolbox.

一般来说,无法从解决方案资源管理器中添加控件,只能从工具箱中添加.

这篇关于如何将我的新用户控件添加到工具箱或新的 Winform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何将我的新用户控件添加到工具箱或新的 Winform?

基础教程推荐