我有一个串属性的类,同时具有吸气和一个setter,也就是常长,所以PropertyGrid的截断的字符串值。我怎样才能迫使PropertyGrid中显示出一个省略号,然后启动一个包含属性的简单的编辑一个多行TextBox的对话?我知道我可能要设置一些种类的财产属性,但属性是什么,以及如何?难道我的对话框必须执行一些特殊的设计界面?

<强>更新 可能是回答我的问题,但我找不到它搜索。我的问题是更普遍,其答案可以用来建立任何类型的自定义编辑器。

有帮助吗?

解决方案

您需要设置一个[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通过观察其行为像你想现有的属性追查现有的编辑器。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top