Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

EditorAttribute Class

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

For a list of all members of this type, see EditorAttribute Members.

System.Object
   System.Attribute
      System.ComponentModel.EditorAttribute

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

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.

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.

Example

[Visual Basic, C#, C++] The following 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.
 }

[C++] 
[Editor(S"System.Windows.Forms.ImageEditorIndex, System.Design", 
        __typeof(UITypeEditor))]

public __gc class MyImage
{
    // Insert code here.
};

[Visual Basic, C#, C++] The next example creates an instance of the MyImage class. Then it gets the attributes for the class, and 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;
 }

[C++] 
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 = dynamic_cast<EditorAttribute*>(attributes->Item[__typeof(EditorAttribute)]);
    Console::WriteLine(S"The editor for this class is: {0}", myAttribute->EditorTypeName);

    return 0;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

EditorAttribute Members | System.ComponentModel Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.