次の方法で共有


BrowsableAttribute クラス

定義

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

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
継承
BrowsableAttribute
属性

次の例では、プロパティをブロウズ可能としてマークします。

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

次の例では、MyPropertyBrowsableAttributeの値を確認する方法を示します。 まず、コードは、オブジェクトのすべてのプロパティを含む PropertyDescriptorCollection を取得します。 次に、コードはMyPropertyを取得するためにPropertyDescriptorCollectionにインデックスを作成します。 次に、このプロパティの属性を返し、属性変数に保存します。

この例では、 BrowsableAttributeの値を確認する 2 つの異なる方法を示します。 2 番目のコード フラグメントでは、この例では Equals メソッドを呼び出します。 最後のコード フラグメントでは、 Browsable プロパティを使用して値を確認します。

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

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

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

注釈

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

プロパティを Browsable(true) でマークすると、この属性の値は定数メンバー Yesに設定されます。 Browsable(false)でマークされたプロパティの場合、値はNo。 そのため、コードでこの属性の値を確認するときは、属性を BrowsableAttribute.Yes または BrowsableAttribute.Noとして指定する必要があります。

詳細については、「属性」を参照してください。

コンストラクター

名前 説明
BrowsableAttribute(Boolean)

BrowsableAttribute クラスの新しいインスタンスを初期化します。

フィールド

名前 説明
Default

BrowsableAttributeの既定値 (Yes) を指定します。 この static フィールドは読み取り専用です。

No

デザイン時にプロパティまたはイベントを変更できないことを指定します。 この static フィールドは読み取り専用です。

Yes

デザイン時にプロパティまたはイベントを変更できることを指定します。 この static フィールドは読み取り専用です。

プロパティ

名前 説明
Browsable

オブジェクトが参照可能かどうかを示す値を取得します。

TypeId

派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。

(継承元 Attribute)

メソッド

名前 説明
Equals(Object)

このインスタンスと指定したオブジェクトが等しいかどうかを示します。

GetHashCode()

このインスタンスのハッシュ コードを返します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

この属性が既定であるかどうかを判断します。

Match(Object)

派生クラスでオーバーライドされた場合、このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

名前 説明
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

インターフェイスの型情報を取得するために使用できるオブジェクトの型情報を取得します。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください