I have a Form that allows user to customized the Chart like changing Color, LegendText and others. I implemented a custom UIEditor below:
class MySeriesCollectionTypeEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (svc != null)
{
Series[] oldSeriesCollection = new Series[] { };
oldSeriesCollection = (Series[])value;
using (MyChartSeriesEditor frm = new MyChartSeriesEditor((Series[])value))
{
if (svc.ShowDialog(frm) == DialogResult.OK)
{
return frm.SeriesCollections;
}
else
{
return oldSeriesCollection;
}
}
}
return value;
}
}
On my MyChartSeriesEditor:
public Series[] SeriesCollections { get; set; }
public OptChartSeriesEditor(Series[] _seriesCollections)
{
InitializeComponent();
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
}
Then the property:
[Browsable(true)]
[Category("Series")]
[DisplayName("SeriesCollections")]
[Editor(typeof(MySeriesCollectionTypeEditor), typeof(UITypeEditor))]
public Series[] SeriesCollections
{
get { return _SeriesCollections; }
set
{
_SeriesCollections = value;
MessageBox.Show("Test Message!");
}
}
When I click on the Ellipsis it shows the Form but when I clicked on either Ok or Cancel, the Form just closes and nothing happened.
Try this approach