VB.NET UserControl

时间:2012-03-23 18:46:01

标签: vb.net user-controls

我正在尝试在VS2010下的VB.net中创建一个UserControl。我有UserControl的代码,我想将它添加到表单。我的问题是,根据我看到的每本书和论坛,在我构建UserControl后,它应该显示在工具箱中。它没有。我甚至从书中下载了代码,代码执行完美,但是他们的TrafficLight控件没有进入工具箱(即使书中说它应该 - 并且设置其属性并将其添加到表单的唯一方法是通过Control属性)。我试图通过声明

手动将控件添加到表单中
Dim myObj As New SomeClass.SomeControl

并在Designer.vb中,与表单上的按钮相同:

Friend WithEvents myObj As SomeClass.SomeControl

两者兼而有之,我收到错误

'myObj' is already declared as 'Friend WithEvents myObj As SomeControl' in this class.

无论哪种方式,当我尝试查看设计时出现错误:

Could not find type 'SomeClass.SomeControl'. Please make sure that the assembly that contains this type is referenced. If this type is part of your development project, make sure the project has been successfully built using settings for your current platform or AnyCPU.

控件本身构建并显示在设计视图中(尽管它不在工具箱中,即使它Imports System.ComponentModelInherits System.Windows.Forms.UserControl以及......还有什么?我试图在单独的内容中构建它项目,看看我是否创建一个单独的dll会有所作为,虽然我真的希望它在同一个项目中 请帮忙 ! (顺便说一句,我已经重新安装了VS2010并且没有用) 谢谢。

1 个答案:

答案 0 :(得分:1)

查看工具/选项/ Windows窗体设计器并将“AutoToolboxPopulate”设置为True(但请注意,如果您有许多(即几十个)用户控件,这可能会花费相当多的时间。