.NET组件编程(3) Property Editor2011-09-26 博客园 mapserver上一章遗留的DefaultValueAttribute问题,还没有找到问题所在,我会继续查找资料,找到后会及时 补上。今天我们讲ComponentProperty Editor UI,在vs环境中Property Editor有两种,一种是vs自带的 ,一种是Component编写者根据自己需求而重新编写的。在本章中我们这两种都会进行一个简单的学习, vs自带的主要讲Collection Editor。先来回顾下我们上章没有讲的几个PropertyAttribute:EditorAttribute:指定Property Editor使用的编辑器。DesignerSerializationVisibilityAttribute:指定通过Property Editor得到的结果是否保存在代码 中。LocalizableAttribute:用户要本地化某个窗体时,任何具有该特性的属性都将自动永久驻留到资源 文件中。代码实例如下,请注意代码中注释说明。using System; using System.Collections.Generic; using System.Collections; using System.Text; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; using System.Drawing.Design; using System.Windows.Forms; using System.Windows.Forms.Design;
namespace Components { // 这个例子用到了vs 2005里的List<>,如果vs 2003的朋友请自己去实做 StudentCollection。 // 只要让Property的类型为继承IList的类型,其Property Editor UI都可以用vs自带的。 public class Demo3 : Component { public Demo3() { _students = new List<Student>(); // 一定要在构造函数中实例话 _students。 }