public override object ConvertFrom( ITypeDescriptorContext context, CultureInfo info, object value) { if (value is string) { try { var s = (string)value; string[] colorsArray = s.Split('|'); var colors = new ColorsTemp(); colors.Normal = Color.FromName(colorsArray[1]); colors.Over = Color.FromName(colorsArray[2]); colors.Down = Color.FromName(colorsArray[0]); } catch { } // if we got this far, complain that we // couldn't parse the string // throw new ArgumentException( "Can not convert '" + (string)value + "' to type ColorsTemp"); } return(base.ConvertFrom(context, info, value)); }
public override object ConvertTo( System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destType) { if (destType == typeof(string) && value is ColorsTemp) { ColorsTemp colors = value as ColorsTemp; return(string.Join("|", new string[] { colors.Normal.Name, colors.Over.Name, colors.Down.Name })); } return(base.ConvertTo(context, culture, value, destType)); }