Designable Components


Designable Components

The .NET Framework provides special support for components that are used in a visual designer. In this section, we'll provide a high-level overview of designable components in the .NET Framework.

In the .NET Framework, a designable component is a class that directly or indirectly derives from System.ComponentModel.Component or implements the System.ComponentModel.IComponent interface. The most significant features of a designable component are as follows :

  • Design-time support

  • Control over external resources

A designable component can be added to the toolbox of a designer such as Microsoft Visual Studio .NET. It can then be dragged and dropped onto a design surface, and, when selected, its properties will be automatically displayed in the property browser. This kind of designer support is not available to a class that does not derive from Component or implement the IComponent interface.

In Chapter 5, "Developing a Simple Custom Control," we will show you how to add a custom control to the toolbox in Visual Studio .NET. If you try to add a class that does not implement IComponent , the user interface to customize the toolbox will inform you that your assembly does not contain components that it can add to the toolbox.

Now let's examine how designable components control external resources. The IComponent interface derives from the System.IDisposable interface, which contains the Dispose method that gives a component a chance to free external resources or references that it holds. Although managed objects are automatically garbage collected, IDisposable allows a class to perform cleanup in a more deterministic manner. This cleanup is required when a class contains references to unmanaged resources that must be explicitly freed, such as database connections. We'll describe how to implement the Dispose method when we look at examples of components that need to free unmanaged resources.

Controls

In the .NET Framework, a control is a designable component that renders a user interface or facilitates the rendering of visual elements. The .NET Framework defines two base control classes:

  • The base class for ASP.NET server controls is System.Web.UI.Control . This class implements the IComponent interface and renders markup text that is used by a client's browser or viewing device to render visual elements.

  • The base class for client-side Windows Forms controls is System.Windows.Forms.Control . This class derives from System.ComponentModel.Component , which implements the IComponent interface. System.Windows.Forms.Control is capable of drawing using GDI+).

Because this book is about server controls, we will not describe client-side Windows Forms controls in any detail. However, when we describe design-time support in Chapter 15, we will briefly look at a few Windows Forms controls because the designer for ASP.NET Web Forms uses Windows Forms controls for features that involve a design-time user interface.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net