[C#.NET][VB.NET] 自訂控制項的集合屬性 /User Control of Collection Properties
2010-07-15 08:45
726 查看
我想弄出像listBox中的Items的集合屬性。
我想到的就是 StringDictionary、StringCollection、List<string>,動手在自訂控制項專案底下加入以下
把這個自訂的控制項拉到測試用的Winform專案底下,觀察屬性,到目前為止看起來一切都很不賴
但是按下"加入"後就掛了
它說string型別出錯,接下來我改測一下int資料型別,看會不會有相同的問題
List<int>集合能夠順利的加入項目
原來我們要使用字串型別集合必須要用到 String Collection Editor
加入以下屬性
or
or
上述語法都能得到相同結果
PS.屬性說明:DesignerSerializationVisibility
這個屬性可以讓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
我想到的就是 StringDictionary、StringCollection、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
相关文章推荐
- [C#.NET][VB.NET] 自訂控制項的自訂集合屬性 /User Control of Custom Collection Properties
- [C#.NET][VB.NET] 自訂控制項的顯示視窗屬性 /User Control of Properties(一)
- [C#.NET][VB.NET] 自訂控制項的自訂屬性編輯視窗 / User Control of Custom Properties Editor
- [C#.NET][VB.NET] 自訂控制項的顯示視窗屬性 /User Control of Properties(二)
- [C#.NET][VB.NET] 自訂控制項的智能標籤-ControlDesigner / User Control of Smart Tag-ControlDesigner
- [C#.NET][VB.NET] 自訂控制項的智能標籤-ComponentDesigner / User Control of Smart Tag-ComponentDesigner
- 【转】[C#.NET][VB.NET] 用 Win32 API 控制 外部應用程式選單
- VB.NET/C# Free Grid Control 免费开源表格控件 - ReoGrid 介绍(1)
- [C#.NET][User Control] 使用 IExtenderProvider 擴充控制項屬性 並 驗証控制項角色 (續)
- (.NET) IntelliSense difference of Extension Method name in Statement Completion for VB and C#.
- VisualC#.NET编写服务器日期控件并使用(UserControl and CustomControl)
- [C#.NET][User Control] 使用 IExtenderProvider 擴充控制項屬性 並 驗証控制項角色
- 获取本机已安装的软件列表C#/VB.NET(Get the list of installed software in local pc)
- ASP.NET 2.0 C# Generics List Collection Folder Control
- [C#.NET][VB.NET] 程式執行時拖曳控制項
- vb.net C# AtlAxGetControl 函数使用方法
- [C#.NET][VB.NET] 一般 / 泛型 Generic Collection 集合型別介紹
- [C#.NET][VB.NET] Winform 應用程式等級的例外捕捉 / Winform of Application Level wicth Exception Catch(转载)
- VB.net对于datagride控件的使用及C#中datagrideView\bindingSource\bindingNavigator\tabcontrol控件的应用
- 为ASP.NET组件加上Collection集合属性(C#)