簡體   English   中英

VB.NET用戶控件

[英]VB.NET UserControl

我正在嘗試在VS2010下的VB.net中創建UserControl。 我有UserControl的代碼,我想將其添加到表單中。 我的問題是,根據我所看到的每本書和論壇,在構建UserControl之后,它應該顯示在“工具箱”中。 沒有。 我什至從書中下載了代碼,代碼執行得很好,但是它們的TrafficLight控件沒有出現在工具箱中(即使書說應該這樣做),設置屬性並將其添加到表單的唯一方法是通過控件屬性)。 我試圖通過聲明將控件手動添加到窗體

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,但效果不好)
謝謝。

在“工具” /“選項” /“ Windows窗體設計器”中查找並將“ AutoToolboxPopulate”設置為True(但是請注意,如果您擁有許多(例如數十個)用戶控件,這可能會花費大量時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM