The Forms Namespace

The System.Windows.Forms namespace is a grouping of classes that comprise the Windows Forms technology. The classes in this namespace provide the ability to create Windows applications, which conform to the standard user interface offered by the Windows operating systems.

The classes contained in the Forms namespace can be grouped into several broad categories.

5.2.1 The Control Class

The System.Windows.Forms.Control class is the base class for all the controls used on a Windows Form. A control is a component that has a visual representation at runtime.

The Control class supplies the basic functionality used by all controls. This basic functionality includes methods, properties, and events to cover:

  • User interaction via keyboard and mouse
  • Receiving and losing focus
  • Size and location
  • Appearance (color, backgrounds, etc.)
  • Parent-child relationships
  • Message routing
  • Window handle (hWnd)
  • Asynchronous processing
  • Security
  • Accessibilitymaking the application usable to everyone, including people with disabilities

5.2.1.1 Ambient properties

Controls enter into a parent-child relationship on the form. The parent acts as a container for the child control. This relationship should not be confused with the base/derived (generalization/specialization) relationship. For example, a panel may act as a parent control to a button and a listbox, even though button and listbox do not derive from a panel.

Some Control class properties, such as Cursor, Font, BackColor and ForeColor, if not explicitly set for a particular instance of a control, will retrieve the property from their parent controls. They are known as ambient properties. Ambient properties allow a control to appear as its parent. If the control does not have a parent and if the property is not set, then a default value is used.

5.2.1.2 The Control inheritance hierarchy

Each specific control used in Windows Forms will be detailed in Chapters 11 through 17. Figure 5-1 is a list of all the classes that derive from the Control class.

Figure 5-1. Classes derived from Control

figs/pnwa_0501.gif

5.2.2 The Form Class

All forms in the .NET Framework are defined in a class, specifically one that inherits from the System.Windows.Forms.Form class. The Form object itself is a control that inherits from the System.Windows.Forms.Control class via the ScrollableControl and ContainerControl classes.

Figure 5-2 lists the class hierarchy that contains the Form class and the classes deriving from it.

Figure 5-2. Form class hierarchy

figs/pnwa_0502.gif

5.2.3 Component Classes

Component classes provide features useful to a Windows application but do not derive from the Control class. They include classes such as ToolTip and ErrorProvider, which provide additional information to the user; timers; menuing classes such as Menu, MenuItem, and ContextMenu; and classes for providing help information, such as Help and HelpProvider. They enable design-time integration of whatever functionality they contain.

5.2.4 CommonDialog Classes

Many applications perform similar functions, such as opening and saving files or selecting fonts. Ever since Windows 3.1, the Windows API has provided standard dialog boxes to perform many of these common operations. Not only does it save the developer from having to reinvent the wheel, but, more importantly, it also makes applications easier to use. Providing a common dialog used by all applications means that users have to learn how to perform each function only once.

The .NET Framework provides several common dialog boxes in the System.Windows.Forms.CommonDialog class, which is a base class for displaying five commonly used Windows dialog boxes. These common dialogs are as follows:

  • FileDialog
  • ColorDialog
  • FontDialog
  • PageSetupDialog
  • PrintDialog

Chapter 6 describes the common dialogs more fully.





Programming. NET Windows Applications
Programming .Net Windows Applications
ISBN: 0596003218
EAN: 2147483647
Year: 2003
Pages: 148
Simiral book on Amazon

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