简体   繁体   中英

VB.NET UserControl

I am trying to create a UserControl in VB.net, under VS2010. I have the code for the UserControl and I would like to add it to a form. 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. 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). 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:

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.
Please help ! (BTW I have reinstalled VS2010 and it did no good)
Thank you.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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