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

ComponentDesigner Class

Extends the design mode behavior of a component.

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

public class ComponentDesigner : ITreeDesigner, IDesigner, IDisposable, 
	IDesignerFilter, IComponentInitializer
public class ComponentDesigner implements ITreeDesigner, IDesigner, 
	IDisposable, IDesignerFilter, IComponentInitializer
public class ComponentDesigner implements ITreeDesigner, IDesigner, 
	IDisposable, IDesignerFilter, IComponentInitializer
Not applicable.

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 IDesignerHost.RootComponent 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.

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 Verbs 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()
        {
        }
    }
}

package ExampleComponent;

import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.Windows.Forms.*;

// Provides an example component designer.
public class ExampleComponentDesigner
    extends System.ComponentModel.Design.ComponentDesigner
{
    public ExampleComponentDesigner()
    {
    } //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 void Initialize(System.ComponentModel.IComponent component)
    {
        // Always call the base Initialize method in an override of this method.
        super.Initialize(component);
    } //Initialize

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

    // This method provides designer verbs.
    /** @property 
     */
    public System.ComponentModel.Design.DesignerVerbCollection get_Verbs()
    {
        return new DesignerVerbCollection(new DesignerVerb[]
            { new DesignerVerb("Example Designer Verb Command",
            new EventHandler(this.OnVerb)) });
    } //get_Verbs

    // 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.");
    } //OnVerb
} //ExampleComponentDesigner

// Provides an example component associated with the example component designer.
/** @attribute DesignerAttribute(ExampleComponentDesigner.class, IDesigner.class)
 */
public class ExampleComponent extends System.ComponentModel.Component
{
    public ExampleComponent()
    {
    } //ExampleComponent
} //ExampleComponent

System.Object
  System.ComponentModel.Design.ComponentDesigner
     Derived Classes
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.