Control Anatomy 101

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); }

Controls all have the same basic anatomy. Just as human anatomy is mostly the same and differs only slightly based on function and form, so is a control's anatomy. Humans share basic properties, such as eye color, hair color, height, and weight. These properties can be used to describe an individual and help form a visual image of the individual. In the same way, various properties of a control define its outward appearance.

A control has one physical part and two logical parts. The physical part is the control window. The control window is the physical space the control occupies on the screen. Within the physical boundary of the control are two logical regions: client and non-client areas. Figure 1.1 shows a basic form showing these areas.

Figure 1.1. Basic Windows Forms control anatomy.

figure 1.1. basic windows forms control anatomy.

The form itself represents the control window. The title bar containing the control box represents the non-client area of the control. The control box contains the minimize, maximize, and close buttons in the upper-right corner of the window. The remaining area of the control window is considered the client area. The client area is where child controls would be located and all painting logic, such as drawing a pie chart, is clipped to the client area. The control window, the client area, and the non-client area are discussed in more detail in the following sections.

Control Window

The main window of a control defines the physical boundary of the control. All messages, such as mouse and keyboard, are sent to the main control window for dispatching. These messages are generated based on user interaction with the current window in focus. The main control window may or may not contain a non-client, or NC, area. Normally, only top-level windows and dialogs contain NC areas. The NC area is generally reserved for the window's main caption and the control box. The remainder of the control area is known as the client area. This is where all other child controls and custom painting logic typically take place.

NC (Non-Client) Area

Often it is not necessary to manage the NC area of a control because the framework handles the painting and management of this area. The underlying windowing framework takes care of providing the system menu, painting the title bar, and placing the control box. In addition, the windowing framework handles the dispatching of commands for the various items, such as system menu items and the minimize/maximize controls.

In recent years, applications have begun to take over the painting and logic of the NC area by providing for gradient-filled title bars or bitmap images within the title-bar area. Such custom painting of the NC area is in the realm of skinning or applying a theme to an application's appearance. Examples of this custom painting logic include WinAmp and Microsoft Media Player. Custom painting makes the application look more individual rather than appearing as part of the collective.

Client Area

As stated previously, the client area of a control is where most of the work, such as child controls and painting, takes place. The client area represents a logic boundary within the main control. This logic boundary can be the same size as the control itself. In the case of a common button, the control consists entirely of a client area. The logical boundary for the client area is not restricted to the size of the control container, but rather the logical client area can be any size. Only the client area visible within the boundaries of the parent control will be rendered on the screen, but the logical size of the client area could be 100 square miles. Of course, I don't suggest a client area that large.



    .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