|
.NET Windows Forms Custom Controls Authors: Weeks R.L Published year: 2002 Pages: 37-38/74 |
Chapter 5 - Advanced Control DevelopmentIN THIS CHAPTER
The process of building custom controls has been greatly simplified due to the richness of the base class libraries available in .NET. Already you possess the knowledge and skill necessary to create a wide assortment of controls. All that remains is learning about the services provided by the base class libraries and the VS .NET support for custom control development. In this chapter, all control and designer base classes, interfaces, events, and attributes are discussed at various levels of detail. In this chapter, more details of the base class libraries, designers, and services are explored. Other than learning what services are available for building controls and their associated designers, an understanding of where to begin or what base class should be used is all that needs to be refined. .NET also introduces the concept of attributes. Attributes are used to provide additional information about classes, properties, methods , and parameters. Control development makes use of various attributes, covered in this chapter, to associate controls with designers and properties with editors. Attributes provide an extremely flexible mechanism for loosely coupling components and promoting reusability. |
Control Base ClassesThe Windows Forms library, like custom controls, uses various base classes for both controls and designers. Often it's helpful to have a point of reference in order to proceed with a new project. A hierarchy of the class structure provides an excellent reference advantage. Figure 5.1 shows the class hierarchy starting with the System.Windows.Forms.Control class. Figure 5.1. The control class hierarchy.
Regardless of the control you intend to build, there exists a base class from which to begin. Notice that a Form is in fact derived from a control base class, the ContainerControl class to be precise. Each level in the hierarchy provides slightly more features and modifies derived behavior to produce the desired result. Picking the proper base class requires that the expected result and functionality of a new control is properly defined. As a guide, use the following questions to help decide what base class to derive from:
Control base classes are not the only classes that can serve as the starting point for the development of a new control. Consider the TabPage control that inherits from the Panel control class. In turn , the Panel control derives from the ScrollableControl base class. When developing a new control, give proper consideration to the base class from which to start. In addition, the same consideration should be given for the control's associated designer. |
|
.NET Windows Forms Custom Controls Authors: Weeks R.L Published year: 2002 Pages: 37-38/74 |