Freigeben über


BrowsableAttribute-Klasse

Gibt an, ob eine Eigenschaft oder ein Ereignis in einem Eigenschaftenfenster angezeigt werden soll.

Namespace: System.ComponentModel
Assembly: System (in system.dll)

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.All)> _
Public NotInheritable Class BrowsableAttribute
    Inherits Attribute
'Usage
Dim instance As BrowsableAttribute
[AttributeUsageAttribute(AttributeTargets.All)] 
public sealed class BrowsableAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::All)] 
public ref class BrowsableAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.All) */ 
public final class BrowsableAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.All) 
public final class BrowsableAttribute extends Attribute

Hinweise

Ein visueller Designer zeigt i. d. R. im Eigenschaftenfenster die Member an, die entweder kein browsebares Attribut aufweisen oder mit dem BrowsableAttribute-Konstruktor mit dem Wert true markiert sind. Diese Member können zur Entwurfszeit geändert werden. Mit dem BrowsableAttribute-Konstruktor mit dem Wert false markierte Member sind für die Bearbeitung zur Entwurfszeit nicht geeignet. Sie werden deshalb nicht in einem visuellen Designer angezeigt. Der Standardwert ist true.

Hinweis

Wenn Sie eine Eigenschaft mit dem BrowsableAttribute-Konstruktor mit dem Wert true markieren, wird der Wert dieses Attributs auf den konstanten Member Yes festgelegt. Für eine mit dem BrowsableAttribute-Konstruktor mit dem Wert false markierte Eigenschaft ist der Wert No. Wenn Sie den Wert im Code überprüfen, müssen Sie dieses Attribut daher als BrowsableAttribute.Yes oder BrowsableAttribute.No angeben.

Weitere Informationen finden Sie unter Übersicht über Attribute und Erweitern von Metadaten mithilfe von Attributen.

Beispiel

Im folgenden Beispiel wird eine Eigenschaft als browsebar markiert.

<Browsable(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property
[Browsable(true)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }
public:
   [Browsable(true)]
   property int MyProperty 
   {
      int get()
      {
         // Insert code here.
         return 0;
      }
      void set( int value )
      {
         // Insert code here.
      }
   }
/** @attribute Browsable(true)
 */
/** @property 
 */
public int get_MyProperty()
{
    // Insert code here.
    return 0;
} //get_MyProperty

/** @property 
 */
public void set_MyProperty(int value)
{
    // Insert code here.
} //set_MyProperty
Browsable(true)
public function get MyProperty() : int {
       // Insert code here.
      return 0;
}

public function set MyProperty(value : int) {
}

Im folgenden Beispiel wird veranschaulicht, wie der Wert von BrowsableAttribute für MyProperty überprüft wird. Zunächst wird im Code eine PropertyDescriptorCollection mit allen Eigenschaften für das Objekt abgerufen. Anschließend wird im Code MyProperty über einen Index der PropertyDescriptorCollection abgerufen. Die Attribute für diese Eigenschaft werden zurückgegeben und in der Variablen attributes gespeichert.

Im Beispiel werden zwei verschiedene Möglichkeiten zum Überprüfen des Werts von BrowsableAttribute gezeigt. Im zweiten Codefragment wird die Equals-Methode aufgerufen. Im letzten Codefragment wird der Wert anhand der Browsable-Eigenschaft überprüft.

' 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 
// 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.
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).
    get_Item("MyProperty").get_Attributes();
// Checks to see if the value of the BrowsableAttribute is Yes.
if (attributes.get_Item(BrowsableAttribute.class.ToType()).Equals(
    BrowsableAttribute.Yes)) {
    // Insert code here.
}
// This is another way to see whether the property is browsable.
BrowsableAttribute myAttribute = (BrowsableAttribute)
    (attributes.get_Item(BrowsableAttribute.class.ToType()));
if (myAttribute.get_Browsable()) {
    // Insert code here.
}
// Gets the attributes for the property.
 var attributes : AttributeCollection  = 
    TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
 
 // Checks to see if the value of the BrowsableAttribute is Yes.
 if(attributes[BrowsableAttribute].Equals(BrowsableAttribute.Yes)) {
    Console.WriteLine("MyProperty is browsable.");
 }
 
 // This is another way to see whether the property is browsable.
 var myAttribute : BrowsableAttribute = 
    BrowsableAttribute(attributes[BrowsableAttribute]);
 if(myAttribute.Browsable) {
    Console.WriteLine("MyProperty is browsable.");
 }

Verwenden Sie zur Prüfung folgenden Code, wenn Sie eine Klasse mit dem BrowsableAttribute markiert haben:

Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(BrowsableAttribute)).Equals(BrowsableAttribute.Yes) Then
    ' Insert code here.
End If 
AttributeCollection attributes = 
    TypeDescriptor.GetAttributes(MyProperty);
 if(attributes[typeof(BrowsableAttribute)].Equals(BrowsableAttribute.Yes)) {
    // Insert code here.
 }
AttributeCollection^ attributes = TypeDescriptor::GetAttributes( MyProperty );
if ( attributes[ BrowsableAttribute::typeid ]->Equals( BrowsableAttribute::Yes ) )
{
   // Insert code here.
}
AttributeCollection attributes = 
    TypeDescriptor.GetAttributes((Int32)get_MyProperty());
if (attributes.get_Item(BrowsableAttribute.class.ToType()).Equals(
    BrowsableAttribute.Yes)) {
    // Insert code here.
}
var attributes : AttributeCollection = 
    TypeDescriptor.GetAttributes(MyProperty);
 if(attributes[BrowsableAttribute].Equals(BrowsableAttribute.Yes)) {
    Console.WriteLine("MyProperty is browsable.");
 }

Vererbungshierarchie

System.Object
   System.Attribute
    System.ComponentModel.BrowsableAttribute

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

BrowsableAttribute-Member
System.ComponentModel-Namespace
Attribute
PropertyDescriptor
EventDescriptor
AttributeCollection-Klasse
PropertyDescriptorCollection