public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string strValue = value as string;
if (strValue != null)
{
string text = strValue.Trim();
if (text.Length == 0)
{
return null;
}
else
{
// Parse 2 integer values.
//
if (culture == null)
{
culture = CultureInfo.CurrentCulture;
}
char sep = culture.TextInfo.ListSeparator[0];
string[] tokens = text.Split(sep);
float[] values = new float[tokens.Length];
TypeConverter floatConverter = TypeDescriptor.GetConverter(typeof(float));
for (int i = 0; i < values.Length; i++)
{
values[i] = (float)floatConverter.ConvertFromString(context, culture, tokens[i]);
}
if (values.Length == 2)
{
return new SizeF(values[0], values[1]);
}
else
{
throw new ArgumentException(SR.Format(SR.TextParseFailedFormat, text, "Width,Height"));
}
}
}
return base.ConvertFrom(context, culture, value);
}