您需要爲該屬性設置一個[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