System.ComponentModel Names ...


.NET Framework Class Library
EditorAttribute Class

Specifies the editor to use to change a property. This class cannot be inherited.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)
Syntax

Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.All, AllowMultiple := True, Inherited := True)> _
Public NotInheritable Class EditorAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As EditorAttribute
C#
[AttributeUsageAttribute(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
public sealed class EditorAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::All, AllowMultiple = true, Inherited = true)]
public ref class EditorAttribute sealed : public Attribute
JScript
public final class EditorAttribute extends Attribute
Remarks

When editing the property, a visual designer should create a new instance of the specified editor through a dialog box or drop-down window.

Use the EditorBaseTypeName property to find this editor's base type. The only available base type is UITypeEditor.

Use the EditorTypeName property to get the name of the type of editor associated with this attribute.

For general information on using attributes. see Attributes Overview and Extending Metadata Using Attributes. For more information on design-time attributes, see Attributes and Design-Time Support.

Examples

The following code example creates the MyImage class. The class is marked with an EditorAttribute that specifies the ImageEditor as its editor.

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

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

The following code example creates an instance of the MyImage class, gets the attributes for the class, and then prints the name of the editor used by myNewImage.

Visual Basic
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
C#
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;
 }
Visual C++
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;
}
Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.ComponentModel..::.EditorAttribute
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Tags :


Page view tracker