ComponentDesigner Class
 

Extends the design mode behavior of a component.

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


Syntax
public class ComponentDesigner : ITreeDesigner, IDesigner, IDisposable, 
	IDesignerFilter, IComponentInitializer
public ref class ComponentDesigner : ITreeDesigner, IDesigner, 
	IDisposable, IDesignerFilter, IComponentInitializer
type ComponentDesigner = 
    class
        interface ITreeDesigner
        interface IDesigner
        interface IDisposable
        interface IDesignerFilter
        interface IComponentInitializer
    end
Public Class ComponentDesigner
	Implements ITreeDesigner, IDesigner, IDisposable, IDesignerFilter,
	IComponentInitializer
Constructors
NameDescription
System_CAPS_pubmethod ComponentDesigner

Initializes a new instance of the ComponentDesigner class.

Properties
NameDescription
System_CAPS_pubproperty

Gets the design-time action lists supported by the component associated with the designer.

System_CAPS_pubproperty

Gets the collection of components associated with the component managed by the designer.

System_CAPS_pubproperty

Gets the component this designer is designing.

System_CAPS_protproperty

Gets an attribute that indicates the type of inheritance of the associated component.

System_CAPS_protproperty

Gets a value indicating whether this component is inherited.

System_CAPS_protproperty

Gets the parent component for this designer.

System_CAPS_protproperty

Gets a collection of property values that override user settings.

System_CAPS_pubproperty

Gets the design-time verbs supported by the component that is associated with the designer.

Methods
NameDescription
System_CAPS_pubmethod Dispose

Releases all resources used by the ComponentDesigner.

System_CAPS_protmethod Dispose

Releases the unmanaged resources used by the ComponentDesigner and optionally releases the managed resources.

System_CAPS_pubmethod DoDefaultAction

Creates a method signature in the source code file for the default event on the component and navigates the user's cursor to that location.

System_CAPS_pubmethod Equals

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethod Finalize

Attempts to free resources by calling Dispose(false) before the object is reclaimed by garbage collection.(Overrides ObjectFinalize.)

System_CAPS_pubmethod GetHashCode

Serves as the default hash function. (Inherited from Object.)

System_CAPS_protmethod GetService

Attempts to retrieve the specified type of service from the design mode site of the designer's component.

System_CAPS_pubmethod GetType

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethod Initialize

Prepares the designer to view, edit, and design the specified component.

System_CAPS_pubmethod InitializeExistingComponent

Reinitializes an existing component.

System_CAPS_pubmethod InitializeNewComponent

Initializes a newly created component.

System_CAPS_pubmethod InitializeNonDefault

Obsolete.Initializes the settings for an imported component that is already initialized to settings other than the defaults.

System_CAPS_protmethod InvokeGetInheritanceAttribute

Gets the InheritanceAttribute of the specified ComponentDesigner.

System_CAPS_protmethod MemberwiseClone

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethod OnSetComponentDefaults

Obsolete.Sets the default properties for the component.

System_CAPS_protmethod PostFilterAttributes

Allows a designer to change or remove items from the set of attributes that it exposes through a TypeDescriptor.

System_CAPS_protmethod PostFilterEvents

Allows a designer to change or remove items from the set of events that it exposes through a TypeDescriptor.

System_CAPS_protmethod PostFilterProperties

Allows a designer to change or remove items from the set of properties that it exposes through a TypeDescriptor.

System_CAPS_protmethod PreFilterAttributes

Allows a designer to add to the set of attributes that it exposes through a TypeDescriptor.

System_CAPS_protmethod PreFilterEvents

Allows a designer to add to the set of events that it exposes through a TypeDescriptor.

System_CAPS_protmethod PreFilterProperties

Allows a designer to add to the set of properties that it exposes through a TypeDescriptor.

System_CAPS_protmethod RaiseComponentChanged

Notifies the IComponentChangeService that this component has been changed.

System_CAPS_protmethod RaiseComponentChanging

Notifies the IComponentChangeService that this component is about to be changed.

System_CAPS_pubmethod ToString

Returns a string that represents the current object.(Inherited from Object.)

Explicit Interface Implementations
NameDescription
System_CAPS_pubinterface System_CAPS_privmethod IDesignerFilterPostFilterAttributes

For a description of this member, see the IDesignerFilterPostFilterAttributes method.

System_CAPS_pubinterface System_CAPS_privmethod IDesignerFilterPostFilterEvents

For a description of this member, see the IDesignerFilterPostFilterEvents method.

System_CAPS_pubinterface System_CAPS_privmethod IDesignerFilterPostFilterProperties

For a description of this member, see the IDesignerFilterPostFilterProperties method.

System_CAPS_pubinterface System_CAPS_privmethod IDesignerFilterPreFilterAttributes

For a description of this member, see the IDesignerFilterPreFilterAttributes method.

System_CAPS_pubinterface System_CAPS_privmethod IDesignerFilterPreFilterEvents

For a description of this member, see the IDesignerFilterPreFilterEvents method.

System_CAPS_pubinterface System_CAPS_privmethod IDesignerFilterPreFilterProperties

For a description of this member, see the IDesignerFilterPreFilterProperties method.

System_CAPS_pubinterface System_CAPS_privproperty

For a description of this member, see the property.

System_CAPS_pubinterface System_CAPS_privproperty

For a description of this member, see the property.

Remarks

The ComponentDesigner base designer class provides a simple designer that can extend the behavior of an associated component in design mode.

ComponentDesigner provides an empty IDesignerFilter interface implementation, whose methods can be overridden to adjust the attributes, properties and events of the associated component at design time.

You can associate a designer with a type using a DesignerAttribute. For an overview of customizing design-time behavior, see Extending Design-Time Support.

The ComponentDesigner class implements a special behavior for the property descriptors of inherited components. An internal type named InheritedPropertyDescriptor is used by the default ComponentDesigner implementation to stand in for properties that are inherited from a base class. There are two cases in which these property descriptors are added.

  1. To the root object itself, which is returned by the property, because you are inheriting from its base class.

  2. To fields found in the base class of the root object. Public and protected fields from the base class are added to the designer so that they can be manipulated by the user.

The InheritedPropertyDescriptor class modifies the default value of a property, so that the default value is the current value at object instantiation. This is because the property is inherited from another instance. The designer defines resetting the property value as setting it to the value that was set by the inherited class. This value may differ from the default value stored in metadata.

Examples

The following code example provides an example ComponentDesigner implementation and an example component associated with the designer. The designer implements an override of the Initialize method that calls the base Initialize method, an override of the DoDefaultAction method that displays a MessageBox when the component is double-clicked, and an override of the property accessor that supplies a custom DesignerVerb menu command to the shortcut menu for the component.

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;

namespace ExampleComponent
{	
    // Provides an example component designer.
    public class ExampleComponentDesigner : System.ComponentModel.Design.ComponentDesigner
    {
        public ExampleComponentDesigner()
        {
        }

        // This method provides an opportunity to perform processing when a designer is initialized.
        // The component parameter is the component that the designer is associated with.
        public override void Initialize(System.ComponentModel.IComponent component)
        {
            // Always call the base Initialize method in an override of this method.
            base.Initialize(component);
        }

        // This method is invoked when the associated component is double-clicked.
        public override void DoDefaultAction()
        {
            MessageBox.Show("The event handler for the default action was invoked.");
        }

        // This method provides designer verbs.
        public override System.ComponentModel.Design.DesignerVerbCollection Verbs
        {
            get
            {
                return new DesignerVerbCollection( new DesignerVerb[] { new DesignerVerb("Example Designer Verb Command", new EventHandler(this.onVerb)) } );
            }
        }

        // Event handling method for the example designer verb
        private void onVerb(object sender, EventArgs e)
        {
            MessageBox.Show("The event handler for the Example Designer Verb Command was invoked.");
        }
    }

    // Provides an example component associated with the example component designer.
    [DesignerAttribute(typeof(ExampleComponentDesigner), typeof(IDesigner))]
    public class ExampleComponent : System.ComponentModel.Component
    {		
        public ExampleComponent()
        {
        }
    }
}
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms

Namespace ExampleComponent

    ' Provides an example component designer.
    Public Class ExampleComponentDesigner
        Inherits System.ComponentModel.Design.ComponentDesigner

        Public Sub New()
        End Sub 'NewNew

        ' This method provides an opportunity to perform processing when a designer is initialized.
        ' The component parameter is the component that the designer is associated with.
        Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
            ' Always call the base Initialize method in an override of this method.
            MyBase.Initialize(component)
        End Sub 'Initialize

        ' This method is invoked when the associated component is double-clicked.
        Public Overrides Sub DoDefaultAction()
            MessageBox.Show("The event handler for the default action was invoked.")
        End Sub 'DoDefaultAction

        ' This method provides designer verbs.
        Public Overrides ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection
            Get
                Return New DesignerVerbCollection(New DesignerVerb() {New DesignerVerb("Example Designer Verb Command", New EventHandler(AddressOf Me.onVerb))})
            End Get
        End Property

        ' Event handling method for the example designer verb
        Private Sub onVerb(ByVal sender As Object, ByVal e As EventArgs)
            MessageBox.Show("The event handler for the Example Designer Verb Command was invoked.")
        End Sub 'onVerb
    End Class 'ExampleComponentDesigner

    ' Provides an example component associated with the example component designer.
    <DesignerAttribute(GetType(ExampleComponentDesigner), GetType(IDesigner))> _
     Public Class ExampleComponent
        Inherits System.ComponentModel.Component

        Public Sub New()
        End Sub 'NewNew
    End Class 'ExampleComponent

End Namespace 'ExampleComponent
#using <System.dll>
#using <System.Design.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Windows::Forms;

// Provides an example component designer.
ref class ExampleComponentDesigner: public ComponentDesigner
{
public:
   ExampleComponentDesigner()
   {
   }

   // This method provides an opportunity to perform processing when a designer is initialized.
   // The component parameter is the component that the designer is associated with.
   virtual void Initialize( IComponent^ component ) override
   {
      // Always call the base Initialize method in an of this method.
      ComponentDesigner::Initialize( component );
   }

   // This method is invoked when the associated component is double-clicked.
   virtual void DoDefaultAction() override
   {
      MessageBox::Show( "The event handler for the default action was invoked." );
   }

   // This method provides designer verbs.
   property DesignerVerbCollection^ Verbs 
   {
      virtual DesignerVerbCollection^ get() override
      {
         array<DesignerVerb^>^ newDesignerVerbs = {gcnew DesignerVerb( "Example Designer Verb Command", gcnew EventHandler( this, &ExampleComponentDesigner::onVerb ) )};
         return gcnew DesignerVerbCollection( newDesignerVerbs );
      }
   }

private:
   // Event handling method for the example designer verb
   void onVerb( Object^ sender, EventArgs^ e )
   {
      MessageBox::Show( "The event handler for the Example Designer Verb Command was invoked." );
   }
};

// Provides an example component associated with the example component designer.

[DesignerAttribute(ExampleComponentDesigner::typeid, IDesigner::typeid)]
ref class ExampleComponent: public Component
{
public:
   ExampleComponent(){}
};
Version Information
.NET Framework
Available since 1.1
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.

Return to top