次の方法で共有


BrowsableAttribute クラス

[プロパティ] ウィンドウにプロパティやイベントを表示するかどうかを指定します。

この型のすべてのメンバの一覧については、BrowsableAttribute メンバ を参照してください。

System.Object
   System.Attribute
      System.ComponentModel.BrowsableAttribute

<AttributeUsage(AttributeTargets.All)>
NotInheritable Public Class BrowsableAttribute   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.All)]
public sealed class BrowsableAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::All)]
public __gc __sealed class BrowsableAttribute : public Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.All)
class BrowsableAttribute extends Attribute

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

通常、ビジュアルなデザイナは、参照できる属性を持たないメンバ、または値 trueBrowsableAttribute コンストラクタを使用してマークされているメンバを [プロパティ] ウィンドウに表示します。これらのメンバはデザイン時に変更できます。値 falseBrowsableAttribute コンストラクタを使用してマークされているメンバは、デザイン時に編集できないため、ビジュアルなデザイナには表示されません。既定値は true です。

メモ   値 trueBrowsableAttribute コンストラクタを使用してプロパティをマークすると、この属性の値は定数メンバ Yes に設定されます。値 falseBrowsableAttribute コンストラクタを使用してマークされているプロパティの場合、値は No になります。したがって、コード内でこの属性の値を確認する場合は、属性を BrowsableAttribute.Yes または BrowsableAttribute.No として指定する必要があります。

詳細については、「 属性の概要 」および「 属性を使用したメタデータの拡張 」を参照してください。

使用例

プロパティを参照可能としてマークする例を次に示します。

 

<Browsable(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

[C#] 
[Browsable(true)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }

[C++] 
public:
    [Browsable(true)]
    __property int get_MyProperty() {
        // Insert code here.
        return 0;
    }
    __property void set_MyProperty( int value ) {
        // Insert code here.
    }


[JScript] 
Browsable(true)
public function get MyProperty() : int {
       // Insert code here.
      return 0;
}

public function set MyProperty(value : int) {
}

MyPropertyBrowsableAttribute の値を確認する方法を次の例に示します。最初に、オブジェクトのすべてのプロパティを保持する PropertyDescriptorCollection を取得します。次に、 PropertyDescriptorCollection にインデックスを付けて、 MyProperty を取得します。そして、このプロパティの属性を返し、その属性を属性変数に保存します。

この例では、 BrowsableAttribute の値を確認する 2 種類の方法を示します。2 番目のコード片では、 Equals メソッドを呼び出します。最後のコード片では、 Browsable プロパティを使用して値を確認します。

 
' 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 

[C#] 
// 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.
 }

[C++] 
// Gets the attributes for the property.
AttributeCollection* attributes = 
    TypeDescriptor::GetProperties(this)->Item[S"MyProperty"]->Attributes;

// Checks to see if the value of the BrowsableAttribute is Yes.
if(attributes->Item[__typeof(BrowsableAttribute)]->Equals(BrowsableAttribute::Yes)) {
    // Insert code here.
}

// This is another way to see whether the property is browsable.
BrowsableAttribute* myAttribute = 
    dynamic_cast<BrowsableAttribute*>(attributes->Item[__typeof(BrowsableAttribute)]);
if(myAttribute->Browsable) {
    // Insert code here.
}

[JScript] 
// 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.");
 }

BrowsableAttribute を使用してクラスをマークした場合は、次のコードを使用して値を確認します。

 
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(BrowsableAttribute)).Equals(BrowsableAttribute.Yes) Then
    ' Insert code here.
End If 

[C#] 
AttributeCollection attributes = 
    TypeDescriptor.GetAttributes(MyProperty);
 if(attributes[typeof(BrowsableAttribute)].Equals(BrowsableAttribute.Yes)) {
    // Insert code here.
 }

[C++] 
AttributeCollection* attributes = 
    TypeDescriptor::GetAttributes( __box(MyProperty));
if(attributes->Item[__typeof(BrowsableAttribute)]->Equals(BrowsableAttribute::Yes)) {
    // Insert code here.
}

[JScript] 
var attributes : AttributeCollection = 
    TypeDescriptor.GetAttributes(MyProperty);
 if(attributes[BrowsableAttribute].Equals(BrowsableAttribute.Yes)) {
    Console.WriteLine("MyProperty is browsable.");
 }

必要条件

名前空間: System.ComponentModel

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System (System.dll 内)

参照

BrowsableAttribute メンバ | System.ComponentModel 名前空間 | Attribute | PropertyDescriptor | EventDescriptor | AttributeCollection | PropertyDescriptorCollection