Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
IDesignerHost Interface
Collapse the table of content
Expand the table of content

IDesignerHost Interface

Provides an interface for managing designer transactions and components.

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

public interface class IDesignerHost : IServiceContainer, IServiceProvider
/** @attribute ComVisibleAttribute(true) */ 
public interface IDesignerHost extends IServiceContainer, IServiceProvider
public interface IDesignerHost extends IServiceContainer, IServiceProvider
Not applicable.

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()
IDesignerHost^ dh = static_cast<IDesignerHost^>(this->Component->Site->GetService( IDesignerHost::typeid ));

// Requests an IDesignerHost service from the design time 
// environment using Component.Site.GetService()
IDesignerHost dh = (IDesignerHost)this.get_Component().get_Site().

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

#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Security::Permissions;

// Provides a form containing a listbox that can display 
// a list of project components.
public ref class DesignerHostListForm: public System::Windows::Forms::Form
   System::Windows::Forms::ListBox^ listBox1;

   System::Windows::Forms::Button^ ok_button;

      this->Name = "DesignerHostListForm";
      this->Text = "List of design-time project components";
      this->listBox1 = gcnew System::Windows::Forms::ListBox;
      this->listBox1->Location = System::Drawing::Point( 8, 8 );
      this->listBox1->Name = "listBox1";
      this->listBox1->Size = System::Drawing::Size( 385, 238 );
      this->listBox1->TabIndex = 0;
      this->listBox1->Anchor = static_cast<AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) | System::Windows::Forms::AnchorStyles::Left) | System::Windows::Forms::AnchorStyles::Right);
      this->ok_button = gcnew System::Windows::Forms::Button;
      this->ok_button->DialogResult = System::Windows::Forms::DialogResult::OK;
      this->ok_button->Location = System::Drawing::Point( 232, 256 );
      this->ok_button->Name = "ok_button";
      this->ok_button->TabIndex = 1;
      this->ok_button->Text = "OK";
      this->ok_button->Anchor = static_cast<AnchorStyles>(System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right);
      this->ClientSize = System::Drawing::Size( 400, 285 );
      array<System::Windows::Forms::Control^>^temp2 = {this->ok_button,this->listBox1};
      this->Controls->AddRange( temp2 );
      this->ResumeLayout( false );


// You can double-click the component of an 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.
public ref class IDesignerHostExampleDesigner: public IDesigner
   System::ComponentModel::IComponent^ component;


   virtual void DoDefaultAction()

   virtual void Initialize( System::ComponentModel::IComponent^ component )
      this->component = component;
      MessageBox::Show( "Double-click the IDesignerHostExample component to view a list of project components." );


   // Displays a list of components in the current design 
   // document when the default action of the designer is invoked.
   void ListComponents()
      DesignerHostListForm^ listform = gcnew DesignerHostListForm;

      // Obtain an IDesignerHost service from the design environment.
      IDesignerHost^ host = dynamic_cast<IDesignerHost^>(this->component->Site->GetService( IDesignerHost::typeid ));

      // Get the project components container (control containment depends on Controls collections)
      IContainer^ container = host->Container;

      // Add each component's type name and name to the list box.
      System::Collections::IEnumerator^ myEnum = container->Components->GetEnumerator();
      while ( myEnum->MoveNext() )
         IComponent^ component = safe_cast<IComponent^>(myEnum->Current);
         listform->listBox1->Items->Add( String::Concat( component->GetType()->Name, " : ", component->Site->Name ) );



   property System::ComponentModel::IComponent^ Component 
      virtual System::ComponentModel::IComponent^ get()
         return this->component;

   property System::ComponentModel::Design::DesignerVerbCollection^ Verbs 
      [PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")]
      virtual System::ComponentModel::Design::DesignerVerbCollection^ get()
         DesignerVerbCollection^ dvc = gcnew DesignerVerbCollection;
         dvc->Add( gcnew DesignerVerb( "List Components",gcnew EventHandler( this, &IDesignerHostExampleDesigner::ListHandler ) ) );
         return dvc;

   void ListHandler( Object^ /*sender*/, EventArgs^ /*e*/ )


// IDesignerHostExampleComponent is a component associated 
// with the IDesignerHostExampleDesigner that demonstrates 
// acquisition and use of the IDesignerHost service 
// to list project components.

public ref class IDesignerHostExampleComponent: public System::ComponentModel::Component


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

Community Additions

© 2015 Microsoft