.NET Framework 提供了可以应用于自定义控件和组件成员的各种属性。 其中一些属性会影响类的运行时行为,而另一些属性会影响设计时行为。
谨慎
此内容是为 .NET Framework 编写的。 如果使用 .NET 6 或更高版本,请谨慎使用此内容。 设计器系统已针对 Windows 窗体进行更改,因此请务必查看自 .NET Framework 以来对设计器所做的更改一文。
控件和组件属性的特性
下表显示了可应用于自定义控件和组件的属性或其他成员的特性。 有关使用其中许多属性的示例,请参阅 如何:在 Windows 窗体控件中应用属性。
特性 | 描述 |
---|---|
AmbientValueAttribute | 指定要传递给属性的值,以导致该属性从另一个源获取其值。 这称为“环境”。 |
BrowsableAttribute | 指定属性或事件是否应在 属性 窗口中显示。 |
CategoryAttribute | 指定当属性或事件显示在一个设置为 Categorized 模式的 PropertyGrid 控件中时,用于对属性或事件分组的类别的名称。 |
DefaultValueAttribute | 指定属性的默认值。 |
DescriptionAttribute | 指定属性或事件的说明。 |
DisplayNameAttribute | 指定不带参数的属性、事件或 public void 方法的显示名称。 |
EditorAttribute | 指定要用于更改属性的编辑器。 |
EditorBrowsableAttribute | 指定可在编辑器中查看的属性或方法。 |
HelpKeywordAttribute | 指定类或成员的上下文关键字。 |
LocalizableAttribute | 指定属性是否应本地化。 |
PasswordPropertyTextAttribute | 指示对象的文本表示形式被星号等字符遮盖。 |
ReadOnlyAttribute | 指定此特性绑定到的属性在设计时是只读还是可读/写。 |
RefreshPropertiesAttribute | 指示当关联的属性值更改时,属性网格应刷新。 |
TypeConverterAttribute | 指定对于此属性绑定到的对象要使用哪种类型作为转换器。 |
数据绑定属性的特性
下表显示了可用于指定自定义控件和组件如何与数据绑定交互的属性。
特性 | 描述 |
---|---|
BindableAttribute | 指定属性是否通常用于绑定。 |
ComplexBindingPropertiesAttribute | 指定组件的数据源和数据成员属性。 |
DefaultBindingPropertyAttribute | 指定组件的默认绑定属性。 |
LookupBindingPropertiesAttribute | 指定组件的数据源和数据成员属性。 |
AttributeProviderAttribute | 启用属性重定向。 |
类的属性
下表显示了可用于在设计时指定自定义控件和组件的行为的属性。
特性 | 描述 |
---|---|
DefaultEventAttribute | 指定组件的默认事件。 |
DefaultPropertyAttribute | 指定组件的默认属性。 |
DesignerAttribute | 指定用于为组件实现设计时服务的类。 |
DesignerCategoryAttribute | 指定类设计器属于某一类别。 |
ToolboxItemAttribute | 表示工具箱项的特性。 |
ToolboxItemFilterAttribute | 指定要用于工具箱项的筛选器字符串和筛选器类型。 |
另请参阅
- Attribute
- 如何在 Windows 窗体控件中应用属性
- 扩展设计时支持
- 使用 .NET Framework 开发自定义 Windows 窗体控件