BrowsableAttribute Classe

Definição

Especifica se uma propriedade ou evento deve ser exibido em uma janela Propriedades.

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
Herança
BrowsableAttribute
Atributos

Exemplos

O exemplo a seguir marca uma propriedade comorowsable.

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

O próximo exemplo mostra como marcar o valor do BrowsableAttribute para MyProperty. Primeiro, o código obtém um PropertyDescriptorCollection com todas as propriedades do objeto . Em seguida, o código indexa no PropertyDescriptorCollection para obter MyProperty. Em seguida, ele retorna os atributos dessa propriedade e os salva na variável de atributos.

O exemplo apresenta duas maneiras diferentes de verificar o valor do BrowsableAttribute. No segundo fragmento de código, o exemplo chama o Equals método . No último fragmento de código, o exemplo usa a Browsable propriedade para marcar o valor.

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

Se você marcou uma classe com o BrowsableAttribute, use o código a seguir para marcar o valor.

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

Comentários

Um designer visual normalmente é exibido no janela Propriedades os membros que não têm nenhum atributo navegável ou são marcados com o BrowsableAttribute parâmetro do browsable construtor definido truecomo . Esses membros podem ser modificados em tempo de design. Os membros marcados com o BrowsableAttribute parâmetro do browsable construtor definido false como não são apropriados para edição em tempo de design e, portanto, não são exibidos em um designer visual. O padrão é true.

Observação

Quando você marca uma propriedade com Browsable(true), o valor desse atributo é definido como o membro Yesconstante . Para uma propriedade marcada com Browsable(false), o valor é No. Portanto, ao marcar o valor desse atributo em seu código, você deve especificar o atributo como BrowsableAttribute.Yes ou BrowsableAttribute.No.

Para obter mais informações, consulte Atributos.

Construtores

BrowsableAttribute(Boolean)

Inicializa uma nova instância da classe BrowsableAttribute.

Campos

Default

Especifica o valor padrão para o BrowsableAttribute, que é Yes. Esse campo static é somente leitura.

No

Especifica se uma propriedade ou um evento não pode ser modificado no tempo de design. Esse campo static é somente leitura.

Yes

Especifica se uma propriedade ou um evento pode ser modificado no tempo de design. Esse campo static é somente leitura.

Propriedades

Browsable

Obtém um valor que indica se um objeto é navegável.

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.

(Herdado de Attribute)

Métodos

Equals(Object)

Indica se essa instância e um objeto especificado são iguais.

GetHashCode()

Retorna o código hash para a instância.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Determina se este atributo é o padrão.

IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a

Confira também