从MSDN总结过来的PropertyGrid中ExpandableObjectConverter的应用
来源:互联网 发布:c语言printf和scanf 编辑:程序博客网 时间:2024/05/22 14:00
public partial class Form1 : Form { public Form1() { InitializeComponent(); AppSettings p = new AppSettings(); this.propertyGrid1.SelectedObject = p; } } /// <summary> /// 对象转换器 /// </summary> public class SpellingOptionsConverter : ExpandableObjectConverter { /// <summary> /// 可否转换到目标类型 /// </summary> /// <param name="context"></param> /// <param name="destinationType">目标类型</param> /// <returns></returns> public override bool CanConvertTo(ITypeDescriptorContext context, System.Type destinationType) { if (destinationType == typeof(SpellingOptions)) return true; return base.CanConvertTo(context, destinationType); } /// <summary> /// 向目标类型转换 /// </summary> /// <param name="context"></param> /// <param name="culture"></param> /// <param name="value">值或引用</param> /// <param name="destinationType">目标类型</param> /// <returns>转换后的返回值</returns> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { if (destinationType == typeof(System.String) && value is SpellingOptions) { SpellingOptions so = (SpellingOptions)value; return "Check while typing:" + so.SpellCheckWhileTyping + ", check CAPS: " + so.SpellCheckCAPS + ", suggest corrections: " + so.SuggestCorrections; } return base.ConvertTo(context, culture, value, destinationType); } /// <summary> /// 可否从源类型转换 /// </summary> /// <param name="context"></param> /// <param name="sourceType">源类型</param> /// <returns></returns> public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType) { if (sourceType == typeof(string)) return true; return base.CanConvertFrom(context, sourceType); } /// <summary> /// 从源类型转换 /// </summary> /// <param name="context"></param> /// <param name="culture"></param> /// <param name="value">值或引用</param> /// <returns></returns> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { try { string s = (string)value; int colon = s.IndexOf(':'); int comma = s.IndexOf(','); if (colon != -1 && comma != -1) { string checkWhileTyping = s.Substring(colon + 1, (comma - colon - 1)); colon = s.IndexOf(':', comma + 1); comma = s.IndexOf(',', comma + 1); string checkCaps = s.Substring(colon + 1, (comma - colon - 1)); colon = s.IndexOf(':', comma + 1); string suggCorr = s.Substring(colon + 1); SpellingOptions so = new SpellingOptions(); so.SpellCheckWhileTyping = Boolean.Parse(checkWhileTyping); so.SpellCheckCAPS = Boolean.Parse(checkCaps); so.SuggestCorrections = Boolean.Parse(suggCorr); return so; } } catch { throw new ArgumentException( "Can not convert '" + (string)value + "' to type SpellingOptions"); } } return base.ConvertFrom(context, culture, value); } }
http://msdn.microsoft.com/zh-cn/library/aa302326.aspx
- 从MSDN总结过来的PropertyGrid中ExpandableObjectConverter的应用
- 各语种的ID列表(从2001版的MSDN中拷贝过来)
- MSDN里的关于.net的PropertyGrid的使用和控件设计的文章。
- 改变PropertyGrid中Property的编辑方式
- wxPython中PropertyGrid控件的简单用法
- 禁用Extjs中propertyGrid的自动排序
- 推荐几个团队博客(从月光博客抠过来的,总结的蛮全的)
- NET 的 PropertyGrid 控件
- 强大的PropertyGrid
- 探索PropertyGrid的使用
- PropertyGrid控件的学习
- PropertyGrid控件的使用
- 只读的PropertyGrid
- propertygrid easyui 的使用
- 从左上角飘过来的广告窗口
- springmvc中从servletRequest中去post发送过来的数据取不到的问题
- VS2010中,如何在“解决方案资源管理器”中显示从别处复制过来的文件夹或文件
- JSP页面中获取从controller中传递过来的时间数据,显示格式
- 重新标记标签矩阵图像
- 第13周实验报告3
- 关于博客
- linux下查看chm文件
- Lost connection to MySQL server during query
- 从MSDN总结过来的PropertyGrid中ExpandableObjectConverter的应用
- 反向链接
- JQuery 利用Ajax判断链接 是否有效
- CentOs、RedHat、Ubuntu下安装jdk6
- C#事件解析
- Android--学习记录--TabHost(非继承TabActivity)
- 快逸报表和weblogic小结
- static响应单击事件
- windows程序设计(5)使用滚动条