How to allow a C # constructor to change a struct property?

I am creating my own Windows Forms control in C # with several custom properties. One of these properties is a simple structure with several integer fields:

public struct Test
{
    public int A, B;
}

Test _Test;

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

I want the Visual Studio designer to edit the fields of my structure in the same way as for Size, Marginsand other similar Windows Forms structures. Do I need to implement my own class-based property editor UITypeEditor, or is there some general "structure editor" provided by the .Net framework?

+3
source share
2 answers

This should do the trick:

[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; }
}
+5
source

All Articles