将用户控件添加到表单

add user control to a form(将用户控件添加到表单)
本文介绍了将用户控件添加到表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有一个 TextBox 和两个按钮的用户控件,但我没有创建事件,只是将它们放置到用户控件中.当我想将用户控件添加到我的表单时,它会说:

<块引用>

无法移动 Task_control.cs.目标文件夹与源文件夹相同.

我不明白为什么.

解决方案

创建用户控件后,您应该构建项目(F6Ctrl+Shift+B).

然后 Visual Studio 会自动将控件添加到 工具箱.您应该将控件从 Toolbox (Ctrl+Alt+X) 拖到表单中.

如果成功构建项目后,控件不在工具箱上,请确保您已将自动填充工具箱设置为true:转到工具->选项,选择Windows Forms Designer节点,将Automatically Populate Toolbox设置为true.

<小时>

您也可以手动将您的用户控件添加到工具箱(如果自动填充工具箱"未设置,并且您不想设置它!).强烈建议您在工具箱上为您的特定用户控件创建一个额外的 选项卡:右键单击工具箱的空白区域并单击 添加选项卡,然后将新标签的名称.

现在构建项目,右键单击工具箱上的空白区域(当然,在您已经创建的选项卡中,或者在常规"选项卡中),然后选择Choose Items::p>

等待几秒钟(或几分钟)让对话框准备就绪,然后单击浏览并选择您的程序集.您的所有用户控件现在都在列表中.选择要添加到工具箱的那些,然后单击确定.

I have created a user control with a TextBox and two Buttons, but I haven't created events, just I place them to user control. When I want to add the user control to my form it says:

Cannot move Task_control.cs. The destination folder is the same as the source folder.

I can't understand why.

解决方案

After creating your user control, you should build the project (F6 or Ctrl+Shift+B).

Then Visual Studio automatically adds the control to the Toolbox. You should drag the control from the Toolbox (Ctrl+Alt+X) to the form.

If after successfully building the project, the control is not on the Toolbox, make sure that you have Automatically Populate Toolbox set to true: Go to Tools->Options, select Windows Forms Designer node, and set Automatically Populate Toolbox to true.


You can also manually add your user control to the toolbox (if "Automatically Populate Toolbox" is not set, and you don't want to set it!). It is highly recommended that you create an additional Tab on the Toolbox for your specific user controls: Right click on an empty area of the Toolbox and click Add Tab, then give the new tab a name.

Now build the project, right click on an empty area on the toolbox (of course, in tab you already created, or in the "General" tab), and select Choose Items:

Wait a few seconds (or minutes) for the dialog to be ready, then click Browse and select your assembly. All of your user controls are now in the list. Select the ones you want to add to the Toolbox and click OK.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)