Я пытался создать свой собственный UITypeEditor, но метод EditValue никогда не вызывается
public class BoundedTextEditor : UITypeEditor
{
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.None;
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
if (value.GetType() != typeof(string)) return value;
var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
var textBox = new TextBox { Text = value.ToString(), Size = new Size(200, 100), MaxLength = 3 };
editorService.DropDownControl(textBox);
return textBox.Text;
}
return value;
}
}
Используется так:
[Editor(typeof(BoundedTextEditor), typeof(UITypeEditor))]
public string KeyTip
{
get
{
return _keyTip;
}
set
{
_keyTip = value;
}
}
Здесь я попытался ограничить строку 3 символами, было бы лучше, если бы это можно было определить с помощью атрибута.