IDesignerHost Interface

 

Provides an interface for managing designer transactions and components.

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

<ComVisibleAttribute(True)>
Public Interface IDesignerHost
	Inherits IServiceContainer, IServiceProvider

NameDescription
System_CAPS_pubpropertyContainer

Gets the container for this designer host.

System_CAPS_pubpropertyInTransaction

Gets a value indicating whether the designer host is currently in a transaction.

System_CAPS_pubpropertyLoading

Gets a value indicating whether the designer host is currently loading the document.

System_CAPS_pubpropertyRootComponent

Gets the instance of the base class used as the root component for the current design.

System_CAPS_pubpropertyRootComponentClassName

Gets the fully qualified name of the class being designed.

System_CAPS_pubpropertyTransactionDescription

Gets the description of the current transaction.

NameDescription
System_CAPS_pubmethodActivate()

Activates the designer that this host is hosting.

System_CAPS_pubmethodAddService(Type, Object)

Adds the specified service to the service container.(Inherited from IServiceContainer.)

System_CAPS_pubmethodAddService(Type, Object, Boolean)

Adds the specified service to the service container, and optionally promotes the service to any parent service containers.(Inherited from IServiceContainer.)

System_CAPS_pubmethodAddService(Type, ServiceCreatorCallback)

Adds the specified service to the service container.(Inherited from IServiceContainer.)

System_CAPS_pubmethodAddService(Type, ServiceCreatorCallback, Boolean)

Adds the specified service to the service container, and optionally promotes the service to parent service containers.(Inherited from IServiceContainer.)

System_CAPS_pubmethodCreateComponent(Type)

Creates a component of the specified type and adds it to the design document.

System_CAPS_pubmethodCreateComponent(Type, String)

Creates a component of the specified type and name, and adds it to the design document.

System_CAPS_pubmethodCreateTransaction()

Creates a DesignerTransaction that can encapsulate event sequences to improve performance and enable undo and redo support functionality.

System_CAPS_pubmethodCreateTransaction(String)

Creates a DesignerTransaction that can encapsulate event sequences to improve performance and enable undo and redo support functionality, using the specified transaction description.

System_CAPS_pubmethodDestroyComponent(IComponent)

Destroys the specified component and removes it from the designer container.

System_CAPS_pubmethodGetDesigner(IComponent)

Gets the designer instance that contains the specified component.

System_CAPS_pubmethodGetService(Type)

Gets the service object of the specified type.(Inherited from IServiceProvider.)

System_CAPS_pubmethodGetType(String)

Gets an instance of the specified, fully qualified type name.

System_CAPS_pubmethodRemoveService(Type)

Removes the specified service type from the service container.(Inherited from IServiceContainer.)

System_CAPS_pubmethodRemoveService(Type, Boolean)

Removes the specified service type from the service container, and optionally promotes the service to parent service containers.(Inherited from IServiceContainer.)

NameDescription
System_CAPS_pubeventActivated

Occurs when this designer is activated.

System_CAPS_pubeventDeactivated

Occurs when this designer is deactivated.

System_CAPS_pubeventLoadComplete

Occurs when this designer completes loading its document.

System_CAPS_pubeventTransactionClosed

Adds an event handler for the TransactionClosed event.

System_CAPS_pubeventTransactionClosing

Adds an event handler for the TransactionClosing event.

System_CAPS_pubeventTransactionOpened

Adds an event handler for the TransactionOpened event.

System_CAPS_pubeventTransactionOpening

Adds an event handler for the TransactionOpening event.

IDesignerHost is an interface that works with the .NET Framework forms designer architecture to provide support for designer transaction and component management.

The .NET Framework does not provide an implementation of this interface. The interface is implemented by development tools that support designers.

Notes to Callers:

To obtain an implementation of IDesignerHost from a development environment, call GetService while your component is active in design mode, passing the type of IDesignerHost to request an IDesignerHost service interface.

IDesignerHost provides the following members related to designer state:

  • The Loading property indicates whether a designer or document is being loaded.

  • The Activated event occurs when a designer is activated before display.

  • The Deactivated event occurs when a designer is deactivated.

  • The LoadComplete event occurs after a document is loaded.

  • The Activate method activates the designer.

IDesignerHost provides the following members related to managing components:

  • The Container property indicates the container for the designer host.

  • The RootComponent property indicates the base class for the root component.

  • The RootComponentClassName property indicates the name of the class of the root component.

  • The CreateComponent method creates the specified type of component.

  • The DestroyComponent method destroys the specified component.

  • The GetDesigner method gets the designer associated with a specified component.

  • The GetType method gets an instance of the type with the specified name.

IDesignerHost provides the following members related to managing transactions:

The following example code demonstrates how to obtain the IDesignerHost service interface from a designer or sited component.

' Requests an IDesignerHost service from the design time environment using Component.Site.GetService()
Dim host As IDesignerHost = CType(Me.Component.Site.GetService(GetType(IDesignerHost)), IDesignerHost)

The following example code demonstrates using the IDesignerHost interface to list project components.

Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms

Namespace IDesignerHostExample

   ' IDesignerHostExampleComponent is a component associated 
   ' with the IDesignerHostExampleDesigner that demonstrates 
   ' acquisition and use of the IDesignerHost service 
   ' to list project components.
    <DesignerAttribute(GetType(IDesignerHostExampleDesigner))> _
    Public Class IDesignerHostExampleComponent
        Inherits System.ComponentModel.Component

        Public Sub New()
        End Sub 'NewNew

        Protected Overloads Sub Dispose(ByVal disposing As Boolean)
            MyBase.Dispose(disposing)
        End Sub 
    End Class 

    ' You can double-click the component of a IDesignerHostExampleDesigner
    ' to show a form containing a listbox that lists the name and type 
    ' of each component or control in the current design-time project.
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    Public Class IDesignerHostExampleDesigner
        Implements IDesigner
        Private component_ As System.ComponentModel.IComponent

        Public Sub New()
        End Sub 'NewNew

        Public Sub DoDefaultAction() Implements IDesigner.DoDefaultAction
            ListComponents()
        End Sub

        Public Sub Initialize(ByVal component As System.ComponentModel.IComponent) Implements IDesigner.Initialize
            Me.component_ = component
            MessageBox.Show("Double-click the IDesignerHostExample component to view a list of project components.")
        End Sub

        ' Displays a list of components in the current design 
        ' document when the default action of the designer is invoked.
        Private Sub ListComponents()

            Using listform As New DesignerHostListForm()

                ' Obtain an IDesignerHost service from the design environment.
                Dim host As IDesignerHost = CType(Me.Component.Site.GetService(GetType(IDesignerHost)), IDesignerHost)
                ' Get the project components container (control containment depends on Controls collections)
                Dim container As IContainer = host.Container
                ' Add each component's type name and name to the list box.
                Dim comp As Component
                For Each comp In container.Components
                    listform.listBox1.Items.Add((comp.GetType().Name + " : " + Component.Site.Name))
                Next comp
                ' Display the form.
                listform.ShowDialog()

            End Using

        End Sub

        Public ReadOnly Property Component() As System.ComponentModel.IComponent Implements IDesigner.Component
            Get
                Return component_
            End Get
        End Property

        Public ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection Implements IDesigner.Verbs
            Get
                Dim dvc As New DesignerVerbCollection()
                dvc.Add(New DesignerVerb("List Components", New EventHandler(AddressOf ListHandler)))
                Return dvc
            End Get
        End Property

        Private Sub ListHandler(ByVal sender As Object, ByVal e As EventArgs)
            ListComponents()
        End Sub

        Public Sub Dispose() Implements IDisposable.Dispose
        End Sub
    End Class
    _ 

    ' Provides a form containing a list box that can display 
    ' a list of project components.
    Public Class DesignerHostListForm
        Inherits System.Windows.Forms.Form
        Public listBox1 As System.Windows.Forms.ListBox
        Private ok_button As System.Windows.Forms.Button

        Public Sub New()
            Me.Name = "DesignerHostListForm"
            Me.Text = "List of design-time project components"
            Me.SuspendLayout()
            Me.listBox1 = New System.Windows.Forms.ListBox()
            Me.listBox1.Location = New System.Drawing.Point(8, 8)
            Me.listBox1.Name = "listBox1"
            Me.listBox1.Size = New System.Drawing.Size(385, 238)
            Me.listBox1.TabIndex = 0
            Me.listBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
            Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right)
            Me.ok_button = New System.Windows.Forms.Button()
            Me.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.ok_button.Location = New System.Drawing.Point(232, 256)
            Me.ok_button.Name = "ok_button"
            Me.ok_button.TabIndex = 1
            Me.ok_button.Text = "OK"
            Me.ok_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
            Me.ClientSize = New System.Drawing.Size(400, 285)
            Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ok_button, Me.listBox1})
            Me.ResumeLayout(False)
        End Sub 

        Protected Overloads Sub Dispose(ByVal disposing As Boolean)
            MyBase.Dispose(disposing)
        End Sub 
    End Class 
End Namespace 

.NET Framework
Available since 1.1
Return to top
Show: