次の方法で共有


EditorAttribute クラス

プロパティを変更するために使用するエディタを指定します。このクラスは継承できません。

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)

構文

'宣言
<AttributeUsageAttribute(AttributeTargets.All, AllowMultiple:=True, Inherited:=True)> _
Public NotInheritable Class EditorAttribute
    Inherits Attribute
'使用
Dim instance As EditorAttribute
[AttributeUsageAttribute(AttributeTargets.All, AllowMultiple=true, Inherited=true)] 
public sealed class EditorAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::All, AllowMultiple=true, Inherited=true)] 
public ref class EditorAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.All, AllowMultiple=true, Inherited=true) */ 
public final class EditorAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.All, AllowMultiple=true, Inherited=true) 
public final class EditorAttribute extends Attribute

解説

プロパティを編集する場合、ビジュアル デザイナはダイアログ ボックスまたはドロップダウン ウィンドウを使用して、指定したエディタの新しいインスタンスを作成する必要があります。

このエディタの基本の型を検索するには、EditorBaseTypeName プロパティを使用します。使用できる基本型は UITypeEditor だけです。

この属性と関連付けられたエディタの型名を取得するには、EditorTypeName プロパティを使用します。

属性の使用方法については、「属性の概要」と「属性を使用したメタデータの拡張」を参照してください。デザイン時の属性の詳細については、「属性とデザイン時サポート」を参照してください。

使用例

MyImage クラスを作成するコード例を次に示します。このクラスは、エディタとして ImageEditor を指定する EditorAttribute を使用してマークされています。

<Editor("System.Windows.Forms.ImageEditorIndex, System.Design", _
    GetType(UITypeEditor))> _
Public Class MyImage
    ' Insert code here.
End Class 'MyImage
[Editor("System.Windows.Forms.ImageEditorIndex, System.Design", 
    typeof(UITypeEditor))]

public class MyImage
{
    // Insert code here.
 }
[Editor("System.Windows.Forms.ImageEditorIndex, System.Design",
UITypeEditor::typeid)]
public ref class MyImage{
   // Insert code here.
};
/** @attribute Editor("System.Windows.Forms.ImageEditorIndex, " 
     + "System.Design", UITypeEditor.class)
 */
public static class MyImage
{
    // Insert code here.
} //MyImage

MyImage クラスのインスタンスを作成し、そのクラスの属性を取得し、myNewImage によって使用されるエディタの名前を出力します。

Public Shared Sub Main()
    ' Creates a new component.
    Dim myNewImage As New MyImage()
    
    ' Gets the attributes for the component.
    Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewImage)
    
    ' Prints the name of the editor by retrieving the EditorAttribute
    ' from the AttributeCollection. 
    
    Dim myAttribute As EditorAttribute = CType(attributes(GetType(EditorAttribute)), EditorAttribute)
    Console.WriteLine(("The editor for this class is: " & myAttribute.EditorTypeName))

End Sub 'Main
public static int Main() {
    // Creates a new component.
    MyImage myNewImage = new MyImage();
 
    // Gets the attributes for the component.
    AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewImage);
 
    /* Prints the name of the editor by retrieving the EditorAttribute 
     * from the AttributeCollection. */
    
    EditorAttribute myAttribute = (EditorAttribute)attributes[typeof(EditorAttribute)];
    Console.WriteLine("The editor for this class is: " + myAttribute.EditorTypeName);
 
    return 0;
 }
int main()
{
   // Creates a new component.
   MyImage^ myNewImage = gcnew MyImage;

   // Gets the attributes for the component.
   AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewImage );

   /* Prints the name of the editor by retrieving the EditorAttribute 
       * from the AttributeCollection. */
   EditorAttribute^ myAttribute = dynamic_cast<EditorAttribute^>(attributes[ EditorAttribute::typeid ]);
   Console::WriteLine( "The editor for this class is: {0}", myAttribute->EditorTypeName );
   return 0;
}
public static void main(String[] args)
{
    // Creates a new component.        
    MyImage myNewImage = new MyImage();

    // Gets the attributes for the component.
    AttributeCollection attributes = 
        TypeDescriptor.GetAttributes(myNewImage);

    /* Prints the name of the editor by retrieving the EditorAttribute 
       from the AttributeCollection. 
     */
    EditorAttribute myAttribute = (EditorAttribute)(
        attributes.get_Item(EditorAttribute.class.ToType()));

    Console.WriteLine("The editor for this class is: " 
        + myAttribute.get_EditorTypeName());
} //main

継承階層

System.Object
   System.Attribute
    System.ComponentModel.EditorAttribute

スレッド セーフ

この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

プラットフォーム

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

参照

関連項目

EditorAttribute メンバ
System.ComponentModel 名前空間