Sdílet prostřednictvím


BrowsableAttribute Třída

Definice

Určuje, zda má být vlastnost nebo událost zobrazena v okně Vlastnosti.

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
Dědičnost
BrowsableAttribute
Atributy

Příklady

Následující příklad označuje vlastnost jako 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.
        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

Další příklad ukazuje, jak zkontrolovat hodnotu BrowsableAttribute pro MyProperty. Nejprve kód získá PropertyDescriptorCollection všechny vlastnosti objektu. Dále se kód indexuje do získání PropertyDescriptorCollectionMyProperty. Pak vrátí atributy pro tuto vlastnost a uloží je do proměnné atributů.

Příklad představuje dva různé způsoby kontroly hodnoty BrowsableAttribute. Ve druhém fragmentu kódu volá příklad metodu Equals . V posledním fragmentu kódu příklad používá Browsable vlastnost ke kontrole hodnoty.

// 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

Pokud jste označili třídu pomocí BrowsableAttributepříkazu , pomocí následujícího kódu zkontrolujte hodnotu.

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

Poznámky

Vizuální návrhář se obvykle zobrazí v okně Vlastnosti členy, které nemají žádný obočí atribut nebo jsou označeny BrowsableAttribute parametrem browsable konstruktoru nastaveným na true. Tyto členy je možné upravovat v době návrhu. Členy označené sadou false parametrů konstruktoru BrowsableAttributebrowsable nejsou vhodné pro úpravy v době návrhu, a proto nejsou zobrazeny ve vizuálním návrháři. Výchozí hodnota je true.

Poznámka:

Když označíte vlastnost Browsable(true)pomocí , hodnota tohoto atributu je nastavena na konstantní člen Yes. Pro vlastnost označenou Browsable(false)hodnotou je Nohodnota . Proto při kontrole hodnoty tohoto atributu v kódu je nutné zadat atribut jako BrowsableAttribute.Yes nebo BrowsableAttribute.No.

Další informace naleznete v tématu Atributy.

Konstruktory

Name Description
BrowsableAttribute(Boolean)

Inicializuje novou instanci BrowsableAttribute třídy.

Pole

Name Description
Default

Určuje výchozí hodnotu pro BrowsableAttributehodnotu , která je Yes. Toto static pole je jen pro čtení.

No

Určuje, že vlastnost nebo událost nelze změnit v době návrhu. Toto static pole je jen pro čtení.

Yes

Určuje, že vlastnost nebo událost lze upravit v době návrhu. Toto static pole je jen pro čtení.

Vlastnosti

Name Description
Browsable

Získá hodnotu určující, zda objekt je browsable.

TypeId

Při implementaci v odvozené třídě získá jedinečný identifikátor pro tento Attribute.

(Zděděno od Attribute)

Metody

Name Description
Equals(Object)

Určuje, zda tato instance a zadaný objekt jsou rovny.

GetHashCode()

Vrátí kód hash pro tuto instanci.

GetType()

Získá Type aktuální instance.

(Zděděno od Object)
IsDefaultAttribute()

Určuje, zda je tento atribut výchozí.

Match(Object)

Při přepsání v odvozené třídě vrátí hodnotu, která určuje, zda se tato instance rovná zadanému objektu.

(Zděděno od Attribute)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

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

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, který lze použít k získání informací o typu pro rozhraní.

(Zděděno od Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od Attribute)

Platí pro

Viz také