Composite Controls

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 discussion of custom controls to this point has assumed a single control or single component. As with most development projects, the end result is a composition of smaller components that in turn create the final product. The same case holds for custom control development. Rather than create a single monolithic control, custom controls are often created by using one or more smaller controls.

Simple controls, such as a command button, require only a single control to provide the necessary functionality. A combo box is a composite control that uses smaller controls to implement the larger control. This design pattern is known as Composition. Composition is a useful design pattern you should explore when creating any custom control that contains several aspects found in simpler controls. The UserControl developed in Chapter 2, "Control Basics," is based on the idea of Composition.

Soft Controls

In the days before 128MB of RAM was standard, developers had to save as many system resources as they could. This is when soft controls came into play. The idea behind soft controls is that the control is not a real control. The control does not have an HWND, or handle to a physical window, but rather is a logical area on the screen. A soft control looks and acts just like a standard control as far as the user is concerned. Only the developer knows that it's not a real control.

Soft controls are often contained within a larger control. The host for the soft control handles the processing of user input and passes along information as needed to the soft control. Such information might include mouse events such as click events. Soft controls provide a lightweight alternative to full-blown controls and are rather easy to implement. Soft controls generally provide painting logic and hit-testing. Hit-testing is used to determine whether a point is located within the boundaries of the soft control. In Chapter 9, "ImageListView Control," a small soft-control scroll button, similar to those found on scrollbars, is developed to demonstrate this useful technique.



    .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