您需要为该属性设置一个[Editor(...)]
,给它一个UITypeEditor
进行编辑;像这样(用你自己的编辑器...)
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
static class Program
{
static void Main()
{
Application.Run(new Form { Controls = { new PropertyGrid { SelectedObject = new Foo() } } });
}
}
class Foo
{
[Editor(typeof(StringEditor), typeof(UITypeEditor))]
public string Bar { get; set; }
}
class StringEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService svc = (IWindowsFormsEditorService)
provider.GetService(typeof(IWindowsFormsEditorService));
if (svc != null)
{
svc.ShowDialog(new Form());
// update etc
}
return value;
}
}
你可能会ABLT追查通过观察其行为像你想现有的属性现有的编辑器。
感谢您的快速回答。我现在给你一个+1,一旦有机会在我的最后尝试,我会将其标记为正确答案。 – flipdoubt 2008-12-11 15:49:46