开发者

Exposing properties of an object contained by a control

I have a simple object, could be a struct even, with three properties that I want to expose to the designer. Basically, I want my property to look like the Size or Padding properties of your average control, with an arrow to collapse or expand the properties as a sub-list of the control's properties. However, I cannot find any reference as to how this can be done. Since there are several types of properties with this collapse/extend look and feel I imagine there's something built-in I can use. If I have to implement my own Designer or Editor, forget it; it's not worth it. I doubt that that's the case; there's gotta be some simple attribute I can stick on the property or class that tells the designer to expose the browsable sub-proper开发者_运维知识库ties.


What you're looking for is called Attributes. Or more specifically Design-Time Attributes

[Category("Hello World")]
[Description("Indicates if Button is Enabled or not")]
[Browsable(true)]
public int Blah { get; set; }


In addition to Yochai's answer, please note the Designer attribute which allows you to set which designer will be used.

By setting the designer type you really have full control on the UI Visual Studio will show for your property.


As Hans said, the solution is to implement a custom TypeConverter. Not worth it for me, so I just flattened the object hierarchy and it works well enough for my purposes. Thanks to all who answered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜