I\'m creating custom control that will draw shape from list (or array) of points. I have basic drawing functionality done, but now I\'m struggling with design-time support i
You can create a custom collection editor deriving CollectionEditor
and set typeof(List
as collection type, also register a new TypeConverterAttribute
for Point
:
// Add reference to System.Design
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.ComponentModel.Design;
public class MyPointCollectionEditor : CollectionEditor
{
public MyPointCollectionEditor() : base(typeof(List)) { }
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
TypeDescriptor.AddAttributes(typeof(Point),
new Attribute[] { new TypeConverterAttribute() });
var result = base.EditValue(context, provider, value);
TypeDescriptor.AddAttributes(typeof(Point),
new Attribute[] { new TypeConverterAttribute(typeof(PointConverter)) });
return result;
}
}
Then it's enough to register it as editor of your List
:
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
public class MyClass : Component
{
public MyClass() { Points = new List(); }
[Editor(typeof(MyPointCollectionEditor), typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List Points { get; private set; }
}