余小章 @ 大內聖殿
祕訣無它, 唯勤而已, by 余小章

导航

 

我想弄出像listBox中的Items的集合屬性。

2010-6-30 上午 11-36-29

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

2010-6-30 上午 11-50-32

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

2010-6-30 上午 11-54-10

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

2010-6-30 上午 11-56-16

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

2010-6-30 上午 11-58-18

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

2010-6-30 下午 12-52-53

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

2010-6-30 下午 12-58-02

加入以下屬性

[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

 

 

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

2010-6-30 下午 01-13-54

PS.屬性說明:DesignerSerializationVisibility

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

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

2010-6-30 下午 01-27-04

參考資料

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

posted on 2010-07-15 08:45  余小章  阅读(1972)  评论(3编辑  收藏  举报