CategoryAttribute クラス
アセンブリ: System (system.dll 内)
構文[AttributeUsageAttribute(AttributeTargets::All)] public ref class CategoryAttribute : public Attribute
解説CategoryAttribute は、PropertyGrid コントロールが Categorized モードに設定されているときに、コントロールに表示するプロパティまたはイベントを関連付けるカテゴリを示します。CategoryAttribute を適用しないプロパティまたはイベントは、PropertyGrid によって Misc カテゴリに関連付けられます。CategoryAttribute のコンストラクタにカテゴリ名を指定することにより、任意の名前でカテゴリを新規作成できます。
Category プロパティは、属性に対応するカテゴリの名前を示します。Category プロパティは、カテゴリ名の透過なローカリゼーションも提供します。
継承時の注意 定義済みの名前以外のカテゴリ名を使用し、カテゴリ名をローカライズする場合は、GetLocalizedString メソッドをオーバーライドする必要があります。また、ローカリゼーションに独自のロジックを採用する場合は、Category プロパティをオーバーライドできます。 CategoryAttribute クラスは、次の共通カテゴリを定義します。| WindowStyle |
使用例MyImage プロパティを作成する例を次に示します。このプロパティには、DescriptionAttribute と CategoryAttribute の 2 つの属性があります。
<Description("The image associated with the control"), _ Category("Appearance")> _ Public Property MyImage() As Image Get ' Insert code here. Return image1 End Get Set ' Insert code here. End Set End Property
[Description("The image associated with the control"),Category("Appearance")] public Image MyImage { get { // Insert code here. return image1; } set { // Insert code here. } }
[Description("The image associated with the control"),Category("Appearance")] System::Drawing::Image^ get() { // Insert code here. return m_Image1; } void set( System::Drawing::Image^ ) { // Insert code here. } }
/** @attribute Description("The image associated with the control") * @attribute Category("Appearance") */ /** @property */ public Image get_MyImage() { // Insert code here. return image1; } //get_MyImage /** @property */ public void set_MyImage(Image value) { // Insert code here. } //set_MyImage
MyImage のカテゴリを取得する例を次に示します。最初に、オブジェクトのすべてのプロパティを保持する PropertyDescriptorCollection を取得します。次に、PropertyDescriptorCollection にインデックスを付けて、MyImage を取得します。そして、このプロパティの属性を返し、その属性を変数 attributes に保存します。
最後に、AttributeCollection から CategoryAttribute を取得し、取得した情報をコンソール画面に書き込むことによって、カテゴリを出力します。
' Gets the attributes for the property. Dim attributes As AttributeCollection = _ TypeDescriptor.GetProperties(Me)("MyImage").Attributes ' Prints the description by retrieving the CategoryAttribute. ' from the AttributeCollection. Dim myAttribute As CategoryAttribute = _ CType(attributes(GetType(CategoryAttribute)), CategoryAttribute) Console.WriteLine(myAttribute.Category)
// Gets the attributes for the property. AttributeCollection attributes = TypeDescriptor.GetProperties(this)["MyImage"].Attributes; // Prints the description by retrieving the CategoryAttribute. // from the AttributeCollection. CategoryAttribute myAttribute = (CategoryAttribute)attributes[typeof(CategoryAttribute)]; Console.WriteLine(myAttribute.Category);
// Gets the attributes for the property. AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyImage" ]->Attributes; // Prints the description by retrieving the CategoryAttribute. // from the AttributeCollection. CategoryAttribute^ myAttribute = static_cast<CategoryAttribute^>(attributes[ CategoryAttribute::typeid ]); Console::WriteLine( myAttribute->Category );
// Gets the attributes for the property. AttributeCollection attributes = TypeDescriptor.GetProperties(this) .get_Item("MyImage").get_Attributes(); // Prints the description by retrieving the CategoryAttribute. // from the AttributeCollection. CategoryAttribute myAttribute = (CategoryAttribute)( attributes.get_Item(CategoryAttribute.class.ToType())); Console.WriteLine(myAttribute.get_Category());
継承階層System.Attribute
System.ComponentModel.CategoryAttribute
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照CategoryAttribute コンストラクタ ()
アセンブリ: System (system.dll 内)
構文
プラットフォームWindows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照CategoryAttribute コンストラクタ (String)
アセンブリ: System (system.dll 内)
構文
解説category パラメータに指定した名前が定義済みのカテゴリ名の場合、その名前は Category プロパティによって自動的にローカライズされます。
指定した名前が定義済みのカテゴリ名ではない場合、および GetLocalizedString メソッドをオーバーライドしてローカライズ後の名前を指定しない場合、その名前はローカライズされません。
プラットフォームWindows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照CategoryAttribute コンストラクタ
オーバーロードの一覧| 名前 | 説明 |
|---|---|
| CategoryAttribute () | Default というカテゴリ名を使用して、CategoryAttribute クラスの新しいインスタンスを初期化します。 |
| CategoryAttribute (String) | 指定したカテゴリ名を使用して、CategoryAttribute クラスの新しいインスタンスを初期化します。 |
参照CategoryAttribute プロパティ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。) |
| WindowStyle | WindowStyle カテゴリを表す CategoryAttribute を取得します。 |
参照CategoryAttribute メソッド
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Equals | オーバーロードされます。 オーバーライドされます。 指定したオブジェクトの値が現在の CategoryAttribute と等しいかどうかを示す値を返します。 |
| GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。) |
| GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。) |
| GetHashCode | オーバーライドされます。 この属性のハッシュ コードを返します。 |
| GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
| IsDefaultAttribute | オーバーライドされます。 この属性が既定値かどうかを判断します。 |
| IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。) |
| Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。) |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
| ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
| GetLocalizedString | 指定したカテゴリのローカライズされた名前を検索します。 |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
参照CategoryAttribute メンバ
PropertyGrid コントロールが [項目別] モードに設定されているときに、コントロールに表示するプロパティまたはイベントを分類するカテゴリの名前を指定します。
CategoryAttribute データ型で公開されるメンバを以下の表に示します。
パブリック コンストラクタ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。) |
| WindowStyle | WindowStyle カテゴリを表す CategoryAttribute を取得します。 |
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Equals | オーバーロードされます。 オーバーライドされます。 指定したオブジェクトの値が現在の CategoryAttribute と等しいかどうかを示す値を返します。 |
| GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。) |
| GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。) |
| GetHashCode | オーバーライドされます。 この属性のハッシュ コードを返します。 |
| GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
| IsDefaultAttribute | オーバーライドされます。 この属性が既定値かどうかを判断します。 |
| IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。) |
| Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。) |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
| ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
| GetLocalizedString | 指定したカテゴリのローカライズされた名前を検索します。 |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
参照- CategoryAttributeのページへのリンク