BrowsableAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定属性或事件是否应在“属性”窗口中显示。
public ref class BrowsableAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class BrowsableAttribute : Attribute
public sealed class BrowsableAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type BrowsableAttribute = class
inherit Attribute
type BrowsableAttribute = class
inherit Attribute
Public NotInheritable Class BrowsableAttribute
Inherits Attribute
- 继承
- 属性
示例
以下示例将属性标记为可浏览。
public:
[Browsable(true)]
property int MyProperty
{
int get()
{
// Insert code here.
return 0;
}
void set( int value )
{
// Insert code here.
}
}
[Browsable(true)]
public int MyProperty
{
get =>
// Insert code here.
0;
set
{
// Insert code here.
}
}
<Browsable(True)> _
Public Property MyProperty() As Integer
Get
' Insert code here.
Return 0
End Get
Set
' Insert code here.
End Set
End Property
下一个示例演示如何检查其MyProperty值BrowsableAttribute。 首先,代码获取 PropertyDescriptorCollection 对象的所有属性。 接下来,代码索引到 PropertyDescriptorCollection 要获取 MyProperty的 。 然后,它将返回此属性的属性,并将其保存在属性变量中。
该示例提供了两种不同的检查值 BrowsableAttribute的方法。 在第二个代码片段中,该示例调用该方法 Equals 。 在最后一个代码片段中,该示例使用 Browsable 属性检查值。
// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyProperty" ]->Attributes;
// Checks to see if the value of the BrowsableAttribute is Yes.
if ( attributes[ BrowsableAttribute::typeid ]->Equals( BrowsableAttribute::Yes ) )
{
// Insert code here.
}
// This is another way to see whether the property is browsable.
BrowsableAttribute^ myAttribute = dynamic_cast<BrowsableAttribute^>(attributes[ BrowsableAttribute::typeid ]);
if ( myAttribute->Browsable )
{
// Insert code here.
}
// Gets the attributes for the property.
AttributeCollection attributes =
TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
// Checks to see if the value of the BrowsableAttribute is Yes.
if (attributes[typeof(BrowsableAttribute)].Equals(BrowsableAttribute.Yes))
{
// Insert code here.
}
// This is another way to see whether the property is browsable.
BrowsableAttribute myAttribute =
(BrowsableAttribute)attributes[typeof(BrowsableAttribute)];
if (myAttribute.Browsable)
{
// Insert code here.
}
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
TypeDescriptor.GetProperties(Me)("MyProperty").Attributes
' Checks to see if the value of the BrowsableAttribute is Yes.
If attributes(GetType(BrowsableAttribute)).Equals(BrowsableAttribute.Yes) Then
' Insert code here.
End If
' This is another way to see whether the property is browsable.
Dim myAttribute As BrowsableAttribute = _
CType(attributes(GetType(BrowsableAttribute)), BrowsableAttribute)
If myAttribute.Browsable Then
' Insert code here.
End If
如果使用
AttributeCollection^ attributes = TypeDescriptor::GetAttributes( MyProperty );
if ( attributes[ BrowsableAttribute::typeid ]->Equals( BrowsableAttribute::Yes ) )
{
// Insert code here.
}
AttributeCollection attributes =
TypeDescriptor.GetAttributes(MyProperty);
if (attributes[typeof(BrowsableAttribute)].Equals(BrowsableAttribute.Yes))
{
// Insert code here.
}
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(BrowsableAttribute)).Equals(BrowsableAttribute.Yes) Then
' Insert code here.
End If
注解
视觉对象设计器通常显示在“属性”窗口中,这些成员要么没有可浏览属性,要么被 BrowsableAttribute 标记为构造函数 browsable 的参数设置为 true。 可以在设计时修改这些成员。 标有 BrowsableAttribute 构造函数 browsable 参数集 false 的成员不适合进行设计时编辑,因此不会显示在可视化设计器中。 默认值为 true。
注释
使用 Browsable(false)的属性,值为 No。 因此,在代码中检查此属性的值时,必须将该属性指定为BrowsableAttribute.Yes或指定。BrowsableAttribute.No
有关更多信息,请参阅特性。
构造函数
| 名称 | 说明 |
|---|---|
| BrowsableAttribute(Boolean) |
初始化 BrowsableAttribute 类的新实例。 |
字段
| 名称 | 说明 |
|---|---|
| Default |
指定 BrowsableAttribute默认值,即 Yes。 此 |
| No |
指定在设计时无法修改属性或事件。 此 |
| Yes |
指定可以在设计时修改属性或事件。 此 |
属性
| 名称 | 说明 |
|---|---|
| Browsable |
获取一个值,该值指示对象是否可浏览。 |
| TypeId |
在派生类中实现时,获取此 Attribute的唯一标识符。 (继承自 Attribute) |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
指示此实例和指定对象是否相等。 |
| GetHashCode() |
返回此实例的哈希代码。 |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| IsDefaultAttribute() |
确定此属性是否为默认值。 |
| Match(Object) |
在派生类中重写时,返回一个值,该值指示此实例是否等于指定对象。 (继承自 Attribute) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |
显式接口实现
| 名称 | 说明 |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
将一组名称映射为对应的一组调度标识符。 (继承自 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
检索对象的类型信息,该信息可用于获取接口的类型信息。 (继承自 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
检索对象提供的类型信息接口的数量(0 或 1)。 (继承自 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供对对象公开的属性和方法的访问。 (继承自 Attribute) |