您的位置:首页 > 编程语言 > VB

[C#.NET][VB.NET] 自訂控制項的集合屬性 /User Control of Collection Properties

2010-07-15 08:45 726 查看
我想弄出像listBox中的Items的集合屬性。





我想到的就是 StringDictionaryStringCollection、List<string>,動手在自訂控制項專案底下加入以下





把這個自訂的控制項拉到測試用的Winform專案底下,觀察屬性,到目前為止看起來一切都很不賴





但是按下"加入"後就掛了





它說string型別出錯,接下來我改測一下int資料型別,看會不會有相同的問題





List<int>集合能夠順利的加入項目





原來我們要使用字串型別集合必須要用到 String Collection Editor





加入以下屬性

[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]

or

[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design", typeof(UITypeEditor))]


or

[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", typeof(UITypeEditor))]

or

[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
參考http://www.windowsdevelop.com/windows-forms-general/usercontrol-collection-property-62761.shtml


上述語法都能得到相同結果





PS.屬性說明:DesignerSerializationVisibility

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

這個屬性可以讓VS自動產生出code來





參考資料

http://www.windowsdevelop.com/windows-forms-general/usercontrol-collection-property-62761.shtml

http://blogs.msdn.com/b/toub/archive/2004/10/12/241277.aspx

http://www.windowsdevelop.com/windows-forms-general/usercontrol-collection-property-62761.shtml

範例下載

CS_UserControl_Collection.zip

VB_UserControl_Collection.zip
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐