简体   繁体   English

在属性网格中编辑自定义类型

[英]Editing custom types in property grid

I have a class MinMax which among other things contains this: 我有一个MinMax类,其中包含以下内容:

public class MinMax
{
    private float m_min = 0;
    private float m_max = 1;
    public override string ToString()
    {
        return m_min + " " + m_max;
    }
}

I also have another class SomeClass with a property of this type: 我还有另一个类SomeClass ,具有此类型的属性:

public MinMax Something
{
    get
    {
        return m_something;
    }
    set
    {
        m_something = value;
    }
}

When I put an object of type SomeClass in a property grid, Something is correctly displayed but for natural reasons I'm not able to edit the value. 当我将类型为SomeClass的对象放在属性网格中时,会正确显示Something内容,但是由于自然原因,我无法编辑该值。

I know I can create a custom type editor and show a custom form to edit it, but I would like to edit the displayed string directly. 我知道我可以创建一个自定义类型编辑器并显示一个自定义表单来对其进行编辑,但是我想直接编辑显示的字符串。

My first solution was to return a string from Something instead but I have other code that needs this property to be returned in it's native format. 我的第一个解决方案是从Something返回一个string ,但是我还有其他代码需要将此属性以其本机格式返回。

Is thera any other convenient solution that will let med edit the value directly as a string in the propertygrid? thera是否有其他方便的解决方案,可以让med在propertygrid中直接将其作为字符串编辑值?

Maybe you're looking for a Custom UITypeEditor : 也许您正在寻找一个Custom UITypeEditor
http://msdn.microsoft.com/en-us/library/ms171840.aspx http://msdn.microsoft.com/en-us/library/ms171840.aspx

For completeness have a look also to TypeConverter , 为了完整TypeConverter ,还可以查看TypeConverter
that can be used to allow simple editing (eg from-to strings) without the need of a custom UITypeEditor : 可用于允许简单的编辑(例如, UITypeEditor字符串),而无需自定义UITypeEditor
http://msdn.microsoft.com/en-us/library/ayybcxe5.aspx http://msdn.microsoft.com/en-us/library/ayybcxe5.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM