Designable ComponentsThe .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 :
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. ControlsIn 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:
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. |