Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14523606
  • 博文数量: 5645
  • 博客积分: 9880
  • 博客等级: 中将
  • 技术积分: 68081
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-28 13:35
文章分类

全部博文(5645)

文章存档

2008年(5645)

我的朋友

分类:

2008-04-28 21:06:14

下载本文示例代码
  msdn中对DefaultValueAttribute的说明为: “可视化设计器可以使用默认值重置成员的值。代码生成器也可使用默认值确定是否为成员生成代码”,我把其理解为了创建Component时,对标示有DefaultValueAttribute的Property产生默认值,Colin Han的解释为:“这个特性可以帮助IDE减少Code生成的工作,如果设计时某个标示有DefaultValueAttribute的Property的值和DefaultValue的值一样,IDE将不会为这个属性生成代码;否则,IDE会自动在InitializeComponent中添加的代码”  举例说明:   Customer Component有个Age Property,声明如下 [Description("Customer's Age"), DefaultValue(20)]public int Age{get { return _age; }set { _age = value; }}   有个窗体Form1,在Form1上贴有一个Customer类型的customer1,在设计时对Age设值为20,Form1的InitializeComponent()为 private void InitializeComponent(){ this.customer1 = new Components.Customer(); //  // customer1 //  this.customer1.Address = null; this.customer1.CreateTime = new System.DateTime(((long)(0))); this.customer1.Id = null; this.customer1.Sex = null;}  如果在设计时对Age设值为40,Form1的InitializeComponent()为: private void InitializeComponent(){ this.customer1 = new Components.Customer(); //  // customer1 //  this.customer1.Address = null; this.customer1.Age = 40; this.customer1.CreateTime = new System.DateTime(((long)(0))); this.customer1.Id = null; this.customer1.Sex = null;}  第二种情况比第一种多了句this.customer1.Age = 40;  本来本文准备讲Component Designer的,但是有朋友问我,用户自定义Property Editor中如何调试的问题,我原来在开发Component的过程都是用MessageBox来弹出信息,但是友人提出了个更好的办法,监视进程,这样就能对用户自定义的Property Editor进行调试,我在vs 6.0里用这种方法调试过,但是在.net环境上我从来我想到过,我想很多朋友在开发过程也可能会遇到这样的问题,至少我是遇到了,而且走了很多的弯路,所以把它作为单独的一章进行讲解下。  先打开一个vs 2005的IDE(IDE1),在IDE1中打开WindowsApplication9解决方案,在Components.Demo3.cs中设置如下断点  再打开一个vs 2005的IDE(IDE2),在IDE1做如下的操作:   在IDE2中打开WindowsApplication9解决方案,并对Demo3的Grade Property设值时,IDE1中会发生断点调试中断。   msdn中对DefaultValueAttribute的说明为: “可视化设计器可以使用默认值重置成员的值。代码生成器也可使用默认值确定是否为成员生成代码”,我把其理解为了创建Component时,对标示有DefaultValueAttribute的Property产生默认值,Colin Han的解释为:“这个特性可以帮助IDE减少Code生成的工作,如果设计时某个标示有DefaultValueAttribute的Property的值和DefaultValue的值一样,IDE将不会为这个属性生成代码;否则,IDE会自动在InitializeComponent中添加的代码”  举例说明:   Customer Component有个Age Property,声明如下 [Description("Customer's Age"), DefaultValue(20)]public int Age{get { return _age; }set { _age = value; }}   有个窗体Form1,在Form1上贴有一个Customer类型的customer1,在设计时对Age设值为20,Form1的InitializeComponent()为 private void InitializeComponent(){ this.customer1 = new Components.Customer(); //  // customer1 //  this.customer1.Address = null; this.customer1.CreateTime = new System.DateTime(((long)(0))); this.customer1.Id = null; this.customer1.Sex = null;}  如果在设计时对Age设值为40,Form1的InitializeComponent()为: private void InitializeComponent(){ this.customer1 = new Components.Customer(); //  // customer1 //  this.customer1.Address = null; this.customer1.Age = 40; this.customer1.CreateTime = new System.DateTime(((long)(0))); this.customer1.Id = null; this.customer1.Sex = null;}  第二种情况比第一种多了句this.customer1.Age = 40;  本来本文准备讲Component Designer的,但是有朋友问我,用户自定义Property Editor中如何调试的问题,我原来在开发Component的过程都是用MessageBox来弹出信息,但是友人提出了个更好的办法,监视进程,这样就能对用户自定义的Property Editor进行调试,我在vs 6.0里用这种方法调试过,但是在.net环境上我从来我想到过,我想很多朋友在开发过程也可能会遇到这样的问题,至少我是遇到了,而且走了很多的弯路,所以把它作为单独的一章进行讲解下。  先打开一个vs 2005的IDE(IDE1),在IDE1中打开WindowsApplication9解决方案,在Components.Demo3.cs中设置如下断点  再打开一个vs 2005的IDE(IDE2),在IDE1做如下的操作:   在IDE2中打开WindowsApplication9解决方案,并对Demo3的Grade Property设值时,IDE1中会发生断点调试中断。 下载本文示例代码


组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试组件编程之自定义属性编辑器的调试
阅读(110) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~