/
ParametersEditor.cs
37 lines (30 loc) · 1.15 KB
/
ParametersEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using Free.Core.Collections;
namespace Free.Core.Design
{
public class ParametersEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
if(context==null||context.Instance==null) return base.GetEditStyle(context);
return typeof(Parameters).IsAssignableFrom(context.PropertyDescriptor.PropertyType)?UITypeEditorEditStyle.Modal:UITypeEditorEditStyle.None;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if(value==null) return value;
if(!(value is Parameters)) return value;
ParametersEditorForm dlg=new ParametersEditorForm(value as Parameters);
IWindowsFormsEditorService editorService=(IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
DialogResult res;
if(editorService!=null) res=editorService.ShowDialog(dlg);
else res=dlg.ShowDialog();
if(res!=DialogResult.OK) return value;
context.OnComponentChanged();
return dlg.Result;
}
}
}