我怎样才能迫使PropertyGrid中显示特定财产定制对话框? [英] How can I force the PropertyGrid to show a custom dialog for a specific property?

查看:152
本文介绍了我怎样才能迫使PropertyGrid中显示特定财产定制对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串属性的一类,同时具有getter和一个setter,往往是这么长时间,PropertyGrid中截断字符串值。我怎样才能迫使PropertyGrid中显示一个省略号,然后启动包含的属性轻松编辑多行文本框的对话?我知道我可能要设置一些的财产属性,但属性是什么,以及如何?难道我的对话框必须执行一些特殊的设计界面?

I have a class with a string property, having both a getter and a setter, that is often so long that the PropertyGrid truncates the string value. How can I force the PropertyGrid to show an ellipsis and then launch a dialog that contains a multiline textbox for easy editing of the property? I know I probably have to set some kind of attribute on the property, but what attribute and how? Does my dialog have to implement some special designer interface?

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

Update: This is probably the answer to my question, but I could not find it by searching. My question is more general, and its answer can be used to build any type of custom editor.

推荐答案

您需要设置一个 的财产,给它一个 UITypeEditor的,做编辑;像这样(用你自己的编辑器...)

You need to set an for the property, giving it a UITypeEditor that does the edit; like so (with your own editor...)

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通过观察其行为像你想现有的属性追查现有的编辑器。

You might be ablt to track down an existing Editor by looking at existing properties that behave like you want.

这篇关于我怎样才能迫使PropertyGrid中显示特定财产定制对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆