Especifica si una propiedad o evento debe mostrarse en una ventana Propiedades.
Espacio de nombres: System.ComponentModel
Ensamblado: System (en system.dll)
Visual Basic (Declaración)
<AttributeUsageAttribute(AttributeTargets.All)> _
Public NotInheritable Class BrowsableAttribute
Inherits Attribute
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
Un diseñador visual suele mostrar en la ventana Propiedades aquellos miembros cuyo atributo no se puede examinar o aquéllos que están marcados con el constructor BrowsableAttribute del valor true. Se puede modificar estos miembros en tiempo de diseño. Los miembros marcados con el constructor BrowsableAttribute del valor false no son adecuados para la edición en tiempo de diseño y, por tanto, no se muestran en un diseñador visual. El valor predeterminado es true.
Nota |
|---|
| Al marcar una propiedad con el constructor BrowsableAttribute del valor true, el valor de este atributo se establece en el miembro de constante Yes. Para una propiedad marcada con el constructor BrowsableAttribute del valor false, el valor es No. Por tanto, cuando compruebe el valor de este atributo en el código, deberá especificar el atributo como BrowsableAttribute.Yes o como BrowsableAttribute.No. |
Para obtener más información, vea Información general sobre atributos y Extender metadatos mediante atributos.
El siguiente ejemplo marca una propiedad como examinable.
<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) {
}
En el siguiente ejemplo se muestra cómo comprobar el valor de BrowsableAttribute para MyProperty. Primero, el código obtiene PropertyDescriptorCollection con todas las propiedades del objeto. A continuación, el código utiliza un índice en PropertyDescriptorCollection para obtener MyProperty. Posteriormente, devuelve los atributos de esta propiedad y los guarda en la variable de atributos.
En el ejemplo se presentan dos formas diferentes de comprobar el valor de BrowsableAttribute. En el segundo fragmento de código del ejemplo, se llama al método Equals. En el último fragmento de código, se utiliza la propiedad Browsable para comprobar el valor.
' 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.");
}
Si se marcó una clase con BrowsableAttribute, debe utilizarse el código siguiente para comprobar el valor.
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.");
}
System.Object
System.Attribute
System.ComponentModel.BrowsableAttribute
Seguridad para subprocesos
Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Windows 98, Windows 2000 SP4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition
.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.
.NET Framework
Compatible con: 2.0, 1.1, 1.0