UserControl 或 Control 的名称属性
Control 或 UserControl 的 Name 属性有什么特别之处,导致它在 Visual Studio 的属性网格内显示为“(Name)
”?
What is special about the Name property of a Control or UserControl that causes it to be displayed as "(Name)
" inside the property grid within Visual Studio?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请查看这篇有关 .NET 中设计时属性的文章。 具体来说,我认为您正在寻找
Browsable
属性,该属性在 Visual Studio 的设计时属性对话框中启用属性。如果您有一个名为
Name
的属性,则可以这样声明它:您可以设置更多属性,例如
Description
、DefaultValue
和Category
,如果您计划向其他开发人员展示您的控件,它将派上用场。编辑:要获得您想要的效果,请同时使用
Browsable
和ParenthesizePropertyName
属性:(感谢 Ksempac 的评论。)
因为您没有指定 if你正在使用 VB 或 C#,VB 中也有同样的事情:
编辑 2:
我想你想知道为什么你想首先用括号将你的属性括起来,或者属性名称的含义是什么?它周围有括号。
您可以在此处找到答案:
基本上,如果某个属性很重要,您希望它出现在排序列表的顶部,因此您将其包围用括号来表明这一点。
Check out this article about design-time attributes in .NET. Specifically, I think you are looking for the
Browsable
attribute, which enables properties in Visual Studio's design-time properties dialogue.If you have a property called
Name
, you'd declare it like this:You can set a lot more attributes, like
Description
,DefaultValue
andCategory
, which will come in handy if you're planning on presenting your controls to other developers.EDIT: To get the effect that you want, use both the
Browsable
andParenthesizePropertyName
attributes:(Thanks to Ksempac from the comments for this.)
Since you didn't specify if you're using VB or C#, here's the same thing in VB:
EDIT 2:
I think you're wondering about why you would want to surround your property with parentheses in the first place, or perhaps what it means for a property's name to have parentheses around it.
You can find the answer to that here:
Basically, if a property is important, you want it to appear at the top of a sorted list, so you surround it with parentheses to indicate this.