公开控件包含的对象的属性

发布于 2024-10-09 02:50:44 字数 241 浏览 0 评论 0原文

我有一个简单的对象,甚至可以是一个结构,具有我想向设计者公开的三个属性。基本上,我希望我的属性看起来像普通控件的“大小”或“填充”属性,并带有一个箭头来折叠或展开属性作为控件属性的子列表。但是,我找不到任何关于如何做到这一点的参考。由于有几种类型的属性具有这种折叠/扩展的外观和感觉,我想有一些内置的东西我可以使用。如果我必须实现自己的设计器或编辑器,那就算了;这是不值得的。我怀疑情况确实如此;必须有一些简单的属性可以粘贴在属性或类上,告诉设计者公开可浏览的子属性。

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-properties.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南薇 2024-10-16 02:50:44

您正在寻找的称为属性。
或者更具体地说设计时属性

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

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; }
风吹雨成花 2024-10-16 02:50:44

除了 Yochai 的回答之外,请注意 Designer 属性,它允许您设置将使用哪个设计器。

通过设置设计器类型,您可以完全控制 Visual Studio 将为您的属性显示的 UI。

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.

清风夜微凉 2024-10-16 02:50:44

正如 Hans 所说,解决方案是实现自定义 TypeConverter。对我来说不值得,所以我只是扁平化了对象层次结构,它对于我的目的来说已经足够好了。感谢所有回答的人。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文