简体   繁体   English

VB.NET用户控件

[英]VB.NET UserControl

I am trying to create a UserControl in VB.net, under VS2010. 我正在尝试在VS2010下的VB.net中创建UserControl。 I have the code for the UserControl and I would like to add it to a form. 我有UserControl的代码,我想将其添加到表单中。 My problem is that, according to every book and forum I have seen, after I build the UserControl, it should show up in the Toolbox. 我的问题是,根据我所看到的每本书和论坛,在构建UserControl之后,它应该显示在“工具箱”中。 It doesn't. 没有。 I even downloaded code from a book, the code executes perfectly, but their TrafficLight control doesn't go in the Toolbox (even though the book says it should - and that the only way to set its properties and to add it to the form is through the Control properties). 我什至从书中下载了代码,代码执行得很好,但是它们的TrafficLight控件没有出现在工具箱中(即使书说应该这样做),设置属性并将其添加到表单的唯一方法是通过控件属性)。 I have tried to add the control to the form manually, by declaring it 我试图通过声明将控件手动添加到窗体

Dim myObj As New SomeClass.SomeControl

and in the Designer.vb, identical with the buttons on the form: 在Designer.vb中,与表单上的按钮相同:

Friend WithEvents myObj As SomeClass.SomeControl

With both, I get an error saying 两者都出现错误

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

And either way, I get an error when I try to look at the design: 无论哪种方式,当我尝试查看设计时都会出错:

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.

The control by itself builds and shows up in design view (not in the Toolbox though, even though it Imports System.ComponentModel and Inherits System.Windows.Forms.UserControl and... what else ? I tried to build it in a separate project, to see if I creating a separate dll will make a difference, though I really want it in the same project. 控件本身会构建并显示在设计视图中(尽管它Imports System.ComponentModelInherits System.Windows.Forms.UserControl和...,但不在工具箱中显示),还有什么呢?我试图在一个单独的项目中构建它,看看我是否创建单独的dll会有所作为,尽管我确实希望在同一项目中使用它。
Please help ! 请帮忙 ! (BTW I have reinstalled VS2010 and it did no good) (顺便说一句,我已经重新安装了VS2010,但效果不好)
Thank you. 谢谢。

在“工具” /“选项” /“ Windows窗体设计器”中查找并将“ AutoToolboxPopulate”设置为True(但是请注意,如果您拥有许多(例如数十个)用户控件,这可能会花费大量时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM