Control Base Classes

function OpenWin(url, w, h) { if(!w) w = 400; if(!h) h = 300; window.open(url, "_new", "width=" + w + ",height=" + h + ",menubar=no,toobar=no,scrollbars=yes", true); }

The 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.

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:

  • Is it a simple control?

    Derive from the Control base class

  • Does the content need scrolling support?

    Derive from the Control or ScrollableControl base class

  • Will the control act as a parent for other controls?

    Derive from the ContainerControl, Panel, or UserControl base class

  • Will the control act like a Form?

    Derive from the UserControl or Form base class

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
    User Interfaces in VB .NET: Windows Forms and Custom Controls
    ISBN: 1590590449
    EAN: 2147483647
    Year: 2002
    Pages: 74

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