日期:2014-05-17  浏览次数:21030 次

c#PropertyGrid怎么修改属性错误的提示信息

图中“经纬度”输入的格式类似于控件的“Size”属性,但是当我输入“q”的时候弹出对话框,对话框中“详细信息”显示“类型‘System.String’。。。”总觉得不好,因为客户看不懂。
我的问题是:能不能修改属性窗口错误提示中的“详细信息”,当然也可以自定义弹出窗口显示并且将值恢复到先前正确的值,“经纬度”是我自定义的类

       public struct 经纬度
        {
            [DefaultValueAttribute(true)]
            public decimal 经度 { get; set; }
            [DefaultValueAttribute(false)]
            public decimal 纬度 { get; set; }
        }

下面是“经纬度”对应的类型转换器

        public class SpellingOptionsConverter : ExpandableObjectConverter
        {

            public override bool CanConvertTo(ITypeDescriptorContext context,
                                   System.Type destinationType)
            {
                if (destinationType == typeof(经纬度))
                    return true;
                return base.CanConvertTo(context, destinationType);
            }
            //这个函数将输入的值转化为 经度+“,”+纬度 显示在“经纬度”上,类似于Size属性
            public override object ConvertTo(ITypeDescriptorContext context,CultureInfo culture,
    object value, System.Type destinationType)
            {
                if (destinationType == typeof(System.String) &&
                     value is 经纬度)
                {
                    经纬度 so = (经纬度)value;
                    return so.经度 + "," + so.纬度;
                }
                return base.ConvertTo(context, culture, value, destinationType);
            }