Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How can I host a designer in my app?

The new DesignSurface class drastically simplifies the code necessary to host a designer in your own application. The following lines of code show the most simple designer that can be created. Note: to run this code, a reference to System.Design.dll will need to be added.

DesignSurface surface = new DesignSurface(typeof(Form));
Control c = surface.View as Control;
if (c != null)
{

  c.Dock = DockStyle.Fill;
  this.Controls.Add(c);
}

In any realistic application that selects, modifies and creates components, instance of IDesignerHost, ISelectionService, IComponentChangeService, and IToolboxService will be needed to interact with the hosted designer.

To see a more real world example of hosting the designer, see the DesignModeDialog sample and the next FAQ question.