BrowsableAttribute 類別

定義

指定屬性 (Property) 或事件是否應該顯示於 [屬性] 視窗中。Specifies whether a property or event should be displayed in a Properties window.

public ref class BrowsableAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class BrowsableAttribute : Attribute
type BrowsableAttribute = class
    inherit Attribute
Public NotInheritable Class BrowsableAttribute
Inherits Attribute
繼承
BrowsableAttribute
屬性

範例

下列範例會將屬性標示為可流覽。The following example marks a property as browsable.

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

下一個範例顯示如何檢查的值BrowsableAttributeMyPropertyThe next example shows how to check the value of the BrowsableAttribute for MyProperty. 首先, 程式碼會取得PropertyDescriptorCollection具有物件之所有屬性的。First, the code gets a PropertyDescriptorCollection with all the properties for the object. 接下來, 程式碼會編制PropertyDescriptorCollection索引, MyProperty以取得。Next, the code indexes into the PropertyDescriptorCollection to get MyProperty. 然後, 它會傳回這個屬性的屬性, 並將其儲存在 attributes 變數中。Then it returns the attributes for this property and saves them in the attributes variable.

此範例會提供兩種不同的方式來檢查的BrowsableAttribute值。The example presents two different ways of checking the value of the BrowsableAttribute. 在第二個程式碼片段中, 此範例Equals會呼叫方法。In the second code fragment, the example calls the Equals method. 在最後一個程式碼片段中, 此範例會Browsable使用屬性來檢查值。In the last code fragment, the example uses the Browsable property to check the value.

// 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, 請使用下列程式碼來檢查值。If you marked a class with the BrowsableAttribute, use the following code to check the value.

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參數標示為。A visual designer typically displays in the Properties window those members that either have no browsable attribute or are marked with the BrowsableAttribute constructor's browsable parameter set to true. 這些成員可以在設計階段修改。These members can be modified at design time. 以此BrowsableAttribute false函式的參數設定為的成員, 不適合設計階段編輯, 因此不會顯示在視覺化設計工具中。 browsableMembers marked with the BrowsableAttribute constructor's browsable parameter set to false are not appropriate for design-time editing and therefore are not displayed in a visual designer. 預設為 trueThe default is true.

注意

當您使用Browsable(true)標記屬性時, 這個屬性的值會設定為常數成員YesWhen you mark a property with Browsable(true), the value of this attribute is set to the constant member Yes. 對於標記Browsable(false)為的屬性, 值為NoFor a property marked with Browsable(false), the value is No. 因此, 當您在程式碼中檢查這個屬性的值時, 您必須將屬性指定BrowsableAttribute.YesBrowsableAttribute.No或。Therefore, when you check the value of this attribute in your code, you must specify the attribute as BrowsableAttribute.Yes or BrowsableAttribute.No.

如需詳細資訊,請參閱屬性For more information, see Attributes.

建構函式

BrowsableAttribute(Boolean)

初始化 BrowsableAttribute 類別的新執行個體。Initializes a new instance of the BrowsableAttribute class.

欄位

Default

指定 BrowsableAttribute 的預設值,就是 YesSpecifies the default value for the BrowsableAttribute, which is Yes. 這個 static 欄位是唯讀的。This static field is read-only.

No

指定在設計階段不可以修改的屬性或事件。Specifies that a property or event cannot be modified at design time. 這個 static 欄位是唯讀的。This static field is read-only.

Yes

指定在設計階段可以修改的屬性或事件。Specifies that a property or event can be modified at design time. 這個 static 欄位是唯讀的。This static field is read-only.

屬性

Browsable

取得值,表示物件是否為可瀏覽。Gets a value indicating whether an object is browsable.

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(繼承來源 Attribute)

方法

Equals(Object)

指示這個執行個體和指定的物件是否相等。Indicates whether this instance and a specified object are equal.

GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsDefaultAttribute()

判斷這個屬性是否為預設值。Determines if this attribute is the default.

Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 Attribute)

適用於

另請參閱