3
votes

I am creating a custom Windows Forms control in C# with several custom properties. One of those properties is a simple struct with several integral 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 the same way as it does for Size, Margins and other similar Windows Forms structures. Do I need to implement a custom property editor based on UITypeEditor class, or is there some common "structure editor" provided by .Net framework?

2
rather than update your title to solved you should add your own answer and, if it is the best one, mark it as the accepted answer. This will help others who have the same problem in the future more than simply editing your question. It will also take it out of the "unanswered" list where many of us go to find people that have questions we can help with. - Yaur
Tried. Got a message "new users must wait 8 hours before answering their own questions". - sharp
@sharp you do not need to answer to your question, but check the most usefull answer - Luca
@sharp - you don't need to edit the title to say solved, just wait till your 8 hours is up then add it as an answer, then wait whatever stand-down period there is before marking it as the answer. - slugster
@slugster Seems to be quite a hassle to do such a simple thing. Waiting and coming back to it 2 times is definitely not what I want to do. Can I just manually close or delete the question without all that complications? - sharp

2 Answers

5
votes

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; }
}