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
下一個範例說明如何檢查 的值BrowsableAttribute。MyProperty 首先,程式碼會取得包含所有物件屬性的 a 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
如果你用 標記了類別 BrowsableAttribute,請使用以下程式碼檢查該值。
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
備註
視覺化設計器通常會在屬性視窗中顯示那些沒有可瀏覽屬性或以建構子browsable參數標記BrowsableAttribute為 true的成員。 這些構件可在設計時進行修改。 標示為 BrowsableAttribute 建構子 browsable 參數為 的 false 成員不適合設計時編輯,因此不會在視覺設計器中顯示。 預設值為 true。
備註
當你標記一個屬性時 Browsable(true),該屬性的值會被設定為常數成員 Yes。 對於標記為 Browsable(false)的屬性,其值為 No。 因此,當你檢查程式碼中該屬性的值時,必須指定 BrowsableAttribute.Yes 為 或 BrowsableAttribute.No。
如需詳細資訊,請參閱屬性。
建構函式
| 名稱 | Description |
|---|---|
| BrowsableAttribute(Boolean) |
初始化 BrowsableAttribute 類別的新執行個體。 |
欄位
| 名稱 | Description |
|---|---|
| Default |
指定 的預設值 BrowsableAttribute,即 Yes。 此 |
| No |
規定屬性或事件在設計時不得被修改。 此 |
| Yes |
規定屬性或事件可在設計時進行修改。 此 |
屬性
| 名稱 | Description |
|---|---|
| Browsable |
會取得一個值,表示物件是否可瀏覽。 |
| TypeId |
在衍生類別中實作時,取得這個 Attribute的唯一標識碼。 (繼承來源 Attribute) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
指出這個實例和指定的物件是否相等。 |
| GetHashCode() |
傳回這個實例的哈希碼。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsDefaultAttribute() |
判斷此屬性是否為預設值。 |
| Match(Object) |
在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。 (繼承來源 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
擷取 物件的型別資訊,可用來取得介面的類型資訊。 (繼承來源 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
擷取物件提供的類型資訊介面數目 (0 或 1)。 (繼承來源 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供物件所公開屬性和方法的存取權。 (繼承來源 Attribute) |