我有一个具有许多属性的PropertyGrid,如下所示:
我想让用户进行调整,但除此之外,我想给他们一个按钮,上面写着“ Guess”,它将尝试为属性选择“最佳”值。我发现UITypeEditor
几乎可以满足我的需求。
我有以下代码
public class GuessMyValueTypeEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
return ((MyClass)context.Instance).GuessMyValue();
}
}
[System.ComponentModel.Category("Adjustable")]
[EditorAttribute(typeof(GuessMyValueTypeEditor), typeof(UITypeEditor))]
public int MyValue
{
get;
set;
}
当用户尝试更改MyValue
时,他会得到一个显示 ... 的按钮。按下时,它将调用我的代码GuessMyValue
,并将属性设置为新值。
这一切都很好,但是我发现“ ...”提示非常不直观。用户希望在按下“ ...”按钮时会看到一个对话框,而我的代码在没有任何用户交互的情况下重置了属性,因此此功能看起来像个bug。
如何将按钮上的提示更改为猜猜?
如果不可能,如何自定义UITypeEditor
以显示我选择的按钮,而不是标准的“编辑”按钮?