我有一个Form
,允许用户自定义Chart
,就像更改Color
,LegendText
等一样。我在下面实现了一个自定义UIEditor:
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;
}
}
在我的MyChartSeriesEditor
上:
public Series[] SeriesCollections { get; set; }
public OptChartSeriesEditor(Series[] _seriesCollections)
{
InitializeComponent();
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
}
然后选择属性:
[Browsable(true)]
[Category("Series")]
[DisplayName("SeriesCollections")]
[Editor(typeof(MySeriesCollectionTypeEditor), typeof(UITypeEditor))]
public Series[] SeriesCollections
{
get { return _SeriesCollections; }
set
{
_SeriesCollections = value;
MessageBox.Show("Test Message!");
}
}
当我单击Ellipsis
时,它会显示Form
,但是当我单击Ok
或Cancel
时,Form
只是关闭而没有任何反应
答案 0 :(得分:0)
尝试这种方法
public Series[] SeriesCollections { get; set; }
public OptChartSeriesEditor(Series[] _seriesCollections)
{
InitializeComponent();
btnOK.Click += (source, e) =>
{
//do some saving or other logic required after ok
this.DialogResult = DialogResult.OK;
this.Close();
};
btnCancel.Click += (source, e) =>
{
this.DialogResult = DialogResult.Cancel;
this.Close();
};
}