Okay, mit PointF scheint das nicht zu gehen, weil es keinen TypeConverter dafür gibt. Ich arbeite anstatt mit PointF nun mit der ohnehin intern verwendeten eigenen Klasse DataPoint, welche wie PointF die Properties X und Y besitzt, welche aber vom Typ Double sind.
Dafür habe ich nun einen eigenen TypeConverter geschrieben, wie es
hier beschrieben ist:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56:
| public class DataPointConverter : ExpandableObjectConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(DataPoint)) return true;
return base.CanConvertTo(context, destinationType); }
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(System.String) && value is DataPoint) { return ((DataPoint)value).X.ToString()+"; "+((DataPoint)value).Y.ToString(); }
return base.ConvertTo(context, culture, value, destinationType); }
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(System.String)) return true;
return base.CanConvertFrom(context, sourceType); }
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value is string) { try{ string s = (string)value; string[] parts = s.Split(new char[] {';'}); DataPoint dp = new DataPoint(); dp.X = Double.Parse(parts[0].Trim()); dp.Y = Double.Parse(parts[1].Trim()); return dp; } catch { throw new ArgumentException("Cannot convert!"); } } return base.ConvertFrom(context, culture, value); } } |
Damit ist das Problem bis auf ein paar Kleinigkeiten gelöst, aber hinter die komme ich noch selber
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".