How to: Access Design-Time Services

The following code example shows you how to gain access to the rich set of .NET Framework services so that you can integrate your components and controls into the design environment.

This code example demonstrates how to access services in your custom designer. A designer class called DemoControlDesigner is attached to a DemoControl class and performs the following operations:

No code example is currently available or this language may not be supported.

The DemoControl class derives from UserControl class, but it requires no special logic to extend its design-time UI. The design-time UI is implemented by the DemoControlDesigner class.

Connecting to Services

The DemoControl class acquires references to various services in its InitializeServices method.

No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.

Service Events

Some services offer events to which your designer can attach. For example, the DemoControlDesigner class attaches event handlers to the ComponentChanged, ComponentAdded, and ComponentRemoved events.

No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.

Implementing the Dispose Method in the Designer

Be careful to detach your event handlers in your designer's Dispose method. This prevents unintended behavior when your designer goes out of scope.

No code example is currently available or this language may not be supported.

Using Services

The DemoControl class uses several services in its smart tag panel. An internal class called DemoActionList is derived from the DesignerActionList class. This class has methods that enable you to create, delete, and enumerate various objects that are available in the design environment. It exposes these methods as smart tags. For example, the following code example uses the GetExtenderProviders method to enumerate all the extender providers present in the design environment.

No code example is currently available or this language may not be supported.

When you make changes to the design-time aspects of a component, you need to rebuild the control project. In addition, if there is another Windows Forms project that is currently open and uses this component, you will probably need to refresh the project to see the changes. Typically, you need to close and reopen the design window containing the component.

Show: