如何让C#设计器编辑我的struct属性?

问题描述 投票:3回答:2

我在C#中使用多个自定义属性创建自定义Windows窗体控件。其中一个属性是一个带有几个整数字段的简单结构:

public struct Test
{
    public int A, B;
}

Test _Test;

[Category("MyCategory")]
public Test TestProperty
{
    get { return _Test; }
    set { _Test = value; }
}

我希望Visual Studio设计器以与SizeMargins和其他类似Windows窗体结构相同的方式编辑结构的字段。我是否需要基于UITypeEditor类实现自定义属性编辑器,或者.Net框架是否提供了一些常见的“结构编辑器”?

c# winforms struct properties designer
2个回答
5
投票

这应该做的伎俩:

[TypeConverter(typeof(ExpandableObjectConverter))]
public struct Test
{
    public int _A, _B;
    public int B
    {
        get { return _B; }
        set { _B = value; }
    }
    public int A
    {
        get { return _A; }
        set { _A = value; }
    }
}

Test _Test;

[Category("MyCategory")]
public Test TestProperty
{
    get { return _Test; }
    set { _Test = value; }
}

0
投票

您需要创建自己的设计师。 http://msdn.microsoft.com/en-us/magazine/cc164048.aspx

© www.soinside.com 2019 - 2024. All rights reserved.