If you have a custom data type like this:
public class CustomSize
{
public int Width { get { /*...*/ } set { /*...*/ } }
public int Height { get { /*...*/ } set { /*...*/ } }
}
Then write this:
public class CustomSizeConverter : ExpandableObjectConverter
{
public override bool GetCreateInstanceSupported( ITypeDescriptorContext context )
{ return true; }
public override object CreateInstance( ITypeDescriptorContext context,
IDictionary propertyValues )
{
CustomSize size = new CustomSize();
size.Width = (int) propertyValues[ (object) "Width" ];
size.Height = (int) propertyValues[ (object) "Height" ];
return size;
}
}
Contributed from George Shepherd's Windows Forms FAQ