添加用户控件到窗体 [英] add user control to a form

查看:216
本文介绍了添加用户控件到窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个文本框和两个按钮的用户控件,但我还没有创建活动,只要我把它们放置到用户控件。当我想给用户控件添加到我的形式,它说:

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:

无法移动Task_control.cs。目标文件夹是一样的源文件夹。

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

我不明白为什么。谢谢!

I don't understand why. Thank you!

推荐答案

创建用户控件后,你应该建立项目(<大骨节病> F6 或<大骨节病>控制 + <大骨节病>移 + <大骨节病>乙)。

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

然后Visual Studio中自动添加控件在工具箱。你应该拖动控制在工具箱(<大骨节病>控制 + <大骨节病>替代 + <大骨节病> X )的形式。

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

如果成功后生成项目,该控制并非在工具箱,请确保您有自动填充工具箱设置为true:转到工具 - >选项,选择 Windows窗体设计节点,将自动填充工具箱真正

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 your user controls are now in the list. Select the ones you want to add to the Toolbox and click OK.

这篇关于添加用户控件到窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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