This documentation is archived and is not being maintained.

IDesigner Interface

Provides the basic framework for building a custom designer.

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

System.IDisposable
   System.ComponentModel.Design.IDesigner

[Visual Basic]
<ComVisible(True)>
Public Interface IDesigner
   Inherits IDisposable
[C#]
[ComVisible(true)]
public interface IDesigner : IDisposable
[C++]
[ComVisible(true)]
public __gc __interface IDesigner : public IDisposable
[JScript]
public
   ComVisible(true)
interface IDesigner implements IDisposable

Classes that Implement IDesigner

Class Description
ComponentDesigner Base designer class for extending the design mode behavior of a component.

Remarks

The IDesigner interface provides an interface through which you can implement basic services for a designer. A designer can modify the behavior of a component at design time, and may provide its own services and behavior. A designer is only active at design-time, and must be associated with a type of component using a DesignerAttribute in order to be loaded when a component of the associated type is created at design time.

The IDesigner interface provides methods and properties that you can implement in order to provide custom behavior at design time.

Implement the Initialize method of a designer to perform actions when a component is created. This can be useful if a component should have a special configuration at design-time, or if its configuration should change depending on conditions that the designer can determine.

A designer can provide menu commands on the shortcut menu that is displayed when a user right-clicks a component or control in the design-time environment. You can implement the Verbs property to define a get accessor that returns a DesignerVerbCollection containing the DesignerVerb objects for generating menu commands.

A designer for a component that appears in the component tray can perform a default action when the component is double-clicked. Implement the DoDefaultAction method to specify the behavior to perform when the component is double-clicked.

A designer can also use the available design-time services to perform a variety of tasks, including surveying the current design-time environment for components and their properties, reading and setting the values of properties of components, managing the toolbox, managing selected components, or displaying a user interface that can be used to configure values or to apply futher processing.

To implement a designer for a control that can be sited on a form, you can inherit from the ControlDesigner class. Controls whose associated designer does not derive from ControlDesigner are displayed in the component tray. The ComponentDesigner and ControlDesigner classes implement the IDesigner interface and provide additional design-time support that may be of use to authors of designers. For more information, see the reference documentation for these classes.

For an overview of creating design components, please see Enhancing Design-Time Support.

Example

[Visual Basic, C#, C++] This example demonstrates an IDesigner implementation that stores a local reference to its component, performs a default action when the component is double-clicked, and provides a designer verb menu command.

[Visual Basic] 
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Data
Imports System.Windows.Forms

' A DesignerAttribute associates the example IDesigner with an example control.
<DesignerAttribute(GetType(ExampleIDesigner))> _
Public Class TestControl
    Inherits System.Windows.Forms.UserControl

    Public Sub New()
    End Sub
End Class

Public Class ExampleIDesigner
    Implements System.ComponentModel.Design.IDesigner

    ' Local reference to the designer's component.
    Private component_ As IComponent

    ' Public accessor to the designer's component.
    Public ReadOnly Property Component() As System.ComponentModel.IComponent Implements IDesigner.Component
        Get
            Return component_
        End Get        
    End Property

    Public Sub New()
    End Sub

    Public Sub Initialize(ByVal component As System.ComponentModel.IComponent) Implements IDesigner.Initialize
        ' This method is called after a designer for a component is created,
        ' and stores a reference to the designer's component.
        Me.component_ = component
    End Sub

    ' This method peforms the 'default' action for the designer. The default action 
    ' for a basic IDesigner implementation is invoked when the designer's component 
    ' is double-clicked. By default, a component associated with a basic IDesigner 
    ' implementation is displayed in the design-mode component tray.
    Public Sub DoDefaultAction() Implements IDesigner.DoDefaultAction
        ' Shows a message box indicating that the default action for the designer was invoked.
        MessageBox.Show("The DoDefaultAction method of an IDesigner implementation was invoked.", "Information")
    End Sub

    ' Returns a collection of designer verb menu items to show in the 
    ' shortcut menu for the designer's component.
    Public ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection Implements IDesigner.Verbs
        Get
            Dim verbs_ As New DesignerVerbCollection()
            Dim dv1 As New DesignerVerb("Display Component Name", New EventHandler(AddressOf Me.ShowComponentName))
            verbs_.Add(dv1)
            Return verbs_
        End Get
    End Property

    ' Event handler for displaying a message box showing the designer's component's name.
    Private Sub ShowComponentName(ByVal sender As Object, ByVal e As EventArgs)
        If Not (Me.Component Is Nothing) Then
            MessageBox.Show(Me.Component.Site.Name, "Designer Component's Name")
        End If
    End Sub

    ' Provides an opportunity to release resources before object destruction.
    Public Sub Dispose() Implements IDesigner.Dispose
    End Sub

End Class

[C#] 
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace IDesignerExample
{    
    // A DesignerAttribute associates the example IDesigner with an example control.
    [DesignerAttribute(typeof(ExampleIDesigner))]
    public class TestControl : System.Windows.Forms.UserControl
    {                
        public TestControl()
        {    
        }
    }

    public class ExampleIDesigner : System.ComponentModel.Design.IDesigner
    {
        // Local reference to the designer's component.
        private IComponent component; 
        // Public accessor to the designer's component.
        public System.ComponentModel.IComponent Component
        {
            get
            {
                return component;
            }            
        }

        public ExampleIDesigner()
        {            
        }

        public void Initialize(System.ComponentModel.IComponent component)
        {
            // This method is called after a designer for a component is created,
            // and stores a reference to the designer's component.
            this.component = component;
        }        
        
        // This method peforms the 'default' action for the designer. The default action 
        // for a basic IDesigner implementation is invoked when the designer's component 
        // is double-clicked. By default, a component associated with a basic IDesigner 
        // implementation is displayed in the design-mode component tray.
        public void DoDefaultAction()
        {
            // Shows a message box indicating that the default action for the designer was invoked.
            MessageBox.Show("The DoDefaultAction method of an IDesigner implementation was invoked.", "Information");
        }

        // Returns a collection of designer verb menu items to show in the 
        // shortcut menu for the designer's component.
        public System.ComponentModel.Design.DesignerVerbCollection Verbs
        {
            get
            {
                DesignerVerbCollection verbs = new DesignerVerbCollection();
                DesignerVerb dv1 = new DesignerVerb("Display Component Name", new EventHandler(this.ShowComponentName));
                verbs.Add( dv1 );
                return verbs;
            }
        }

        // Event handler for displaying a message box showing the designer's component's name.
        private void ShowComponentName(object sender, EventArgs e)
        {
            if( this.Component != null )
                MessageBox.Show( this.Component.Site.Name, "Designer Component's Name" );
        }

        // Provides an opportunity to release resources before object destruction.
        public void Dispose()
        {        
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.dll>
using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Data;
using namespace System::Windows::Forms;

public __gc class ExampleIDesigner : public System::ComponentModel::Design::IDesigner
{
    // Local reference to the designer's component.
private:
    IComponent* component; 
    // Public accessor to the designer's component.
public:
    __property System::ComponentModel::IComponent* get_Component()
    {
        return component;
    }            

    ExampleIDesigner()
    {            
    }

    void Initialize(System::ComponentModel::IComponent* component)
    {
        // This method is called after a designer for a component is created,
        // and stores a reference to the designer's component.
        this->component = component;
    }        

    // This method peforms the 'default' action for the designer. The default action 
    // for a basic IDesigner implementation is invoked when the designer's component 
    // is double-clicked. By default, a component associated with a basic IDesigner 
    // implementation is displayed in the design-mode component tray.
    void DoDefaultAction()
    {
        // Shows a message box indicating that the default action for the designer was invoked.
        MessageBox::Show(S"The DoDefaultAction method of an IDesigner implementation was invoked.", S"Information");
    }

    // Returns a collection of designer verb menu items to show in the 
    // shortcut menu for the designer's component.
    __property System::ComponentModel::Design::DesignerVerbCollection* get_Verbs()
    {
        DesignerVerbCollection* verbs = new DesignerVerbCollection();
        DesignerVerb* dv1 = new DesignerVerb(S"Display Component Name", new EventHandler(this, &ExampleIDesigner::ShowComponentName));
        verbs->Add( dv1 );
        return verbs;
    }

    // Event handler for displaying a message box showing the designer's component's name.
private:
    void ShowComponentName(Object* /*sender*/, EventArgs* /*e*/)
    {
        if( this->Component != 0 )
            MessageBox::Show( this->Component->Site->Name, S"Designer Component's Name" );
    }

    // Provides an opportunity to release resources before object destruction.
public:
    void Dispose()
    {        
    }
};

// A DesignerAttribute associates the example IDesigner with an example control.
[DesignerAttribute(__typeof(ExampleIDesigner))]
public __gc class TestControl : public System::Windows::Forms::UserControl
{                
public:
    TestControl()
    {    
    }
};

[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.Design

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

IDesigner Members | System.ComponentModel.Design Namespace | IRootDesigner | IDesignerHost | DesignerVerb | Enhancing Design-Time Support

Show: