我不能在winform c#.net中使用UserControls [英] I can't use UserControls in winform c#.net

查看:164
本文介绍了我不能在winform c#.net中使用UserControls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


我创建了一个用户控件并编译了解决方案。



在工具箱中编译后,控制即将到来。



但是当我拖放到表单时,它显示错误消息:无法加载工具箱项'控制名'它将被删除工具箱。



......现在它也将从工具箱中删除。



什么是问题还是解决方案是什么?



这是VS2013的错误吗?因为如果我创建一个新项目,我首先设计用户控件,然后添加dll项目。我可以将控件拖到我的表单中。没有什么问题?这很奇怪。

解决方案

... 6月5日编辑...基于表明Visual Studio Express没有Windows窗体控件库的研究模板...



假设您正在使用:Visual Studio Express 2013 for Windows Desktop,请尝试:



1.打开新项目,选择类库的项目类型



2.手动添加对System.Windows.Forms的引用和System.Drawing以及UserControl需要的任何其他引用



3.添加UserControl:设计它,编码。



4.编译/保存此项目时,它将创建一个.dll



在新的WinForms应用程序项目中重用UserControl: br $>


1.选择工具箱选项卡,上下文选择添加新项目



2.选择浏览:导航到您创建UserControl的类库的项目



3.找到该类Lbrary项目的编译.dll:选择它:希望它会出现在工具箱中





... 6月5日结束编辑...



清单:



0. UserControl有一个无参数构造函数?



1.你创建的UserControl没有间接依赖于其他文件,dll,控件,表单等?



2.您将UserControl创建为类型为Windows Forms Control的项目库?



3.你创建了一个新的WinForms项目,你想重新使用已编译的UserControl,其中:



a。你在上面的某个现有标签中的工具箱上单击了上下文,选择了添加新项目,然后在选择器对话框窗体中浏览到UserControl dll?



b。 UserControl现在出现在ToolBox中?



4.你注册/安装了UserControl的程序集吗? (如果你希望每次打开一个新项目时Control都会在ToolBox中保留)...我怀疑这与你无关,但是,如果是,请参阅:[ ^ ]


这不是VS错误 - 我经常使用UserControls,这通常是因为无参数构造函数中的代码抛出异常。要么注释掉构造函数代码并慢慢添加它,要么在运行时创建一个实例,并使用调试器找出它失败的原因。


只需清理并重建项目

hi
I have created a User control and compiled the solution.

After compilation in Tool Box, that control is comming.

But when I drag drop to the form, its showing error message: "Failed to load toolbox item 'controle name' it will be removed from the toolbox. "

... and now it will be removed from the ToolBox too.

What is the problem or what is the solution?

Is that a bug of VS2013? Beacause if I create a new project, I design the user control first, and then add dll project. I can drag the control into my form. There is nothing wrong with it? That's weird.

解决方案

... June 5 edit ... based on research that indicates that Visual Studio Express does not have the "Windows Forms Control Library" template ...

Assuming you are using: Visual Studio Express 2013 for Windows Desktop, try this:

1. Open New Project, Select a Project Type of 'Class Library'

2. Manually add the references to System.Windows.Forms and System.Drawing and any other references your UserControl requires

3. Add a UserControl: design it, code it.

4. When you compile/save this Project it will create a .dll

To re-use the UserControl in a new WinForms Application Project:

1. Select a ToolBox Tab, context-select "Add New Item"

2. Choose Browse: navigate to the Project of type Class Library where you created the UserControl

3. find the compiled .dll for that Class Lbrary Project: select it: hopefully it will appear in the ToolBox


... end June 5 edit ...

Checklist:

0. the UserControl has a parameterless constructor ?

1. you created the UserControl with no indirect dependencies on other files, dll's, Controls, Forms, etc. ?

2. you created the UserControl as a Project of Type "Windows Forms Control Library" ?

3. you created a new WinForms project where you wanted to re-use the compiled UserControl where:

a. you context-clicked on the ToolBox in some existing Tab, selected 'Add New Item' and then browsed in the selector dialog Form to the UserControl dll ?

b. the UserControl now appears in the ToolBox ?

4. did you register/install the Assembly of the UserControl ? (if you expect the Control to persist in the ToolBox every time you open a new project) ... I suspect this is not relevant to you, but, if it is, see: [^]


It's not a VS Bug - I use UserControls a lot, and it's normally because code in your parameterless Constructor is throwing an exception. Either comment out the constructor code and slowly add it back, or create an instance at run time and use the debugger to find out why it's failing.


just clean and rebuild the project


这篇关于我不能在winform c#.net中使用UserControls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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