Summary Windows Forms I: Developing Desktop Applications

186 Figure 4-16. Hello, Printer in a print preview window

4.7.9 Summary of Printing

The .NET Framework hides the mechanics of printing. Applications dont have to know how to find printers, they dont have to know what a given printers capabilities are, and they dont have to know how to issue commands that are meaningful to a given brand of printer. The Framework abstracts all of this away. However, the Framework doesnt know anything about a given applications documents. It is up to the application developer to know how to paginate the applications documents and render each page in response to each call to the PrintDocument classs OnPrintPage method.

4.8 Summary

In this chapter, youve seen how to work with Windows forms in creating a desktop application. A Windows form, however, is simply a container for the applications user interface components. In the next chapter, youll round out your examination of desktop application development by looking at controls, common dialogs, and menus. 187

Chapter 5. Windows Forms II: Controls, Common Dialog Boxes, and Menus

By themselves, one or more forms provide very little functionality to most desktop applications. For the most part, forms are valuable insofar as they serve as containers for controls. In this chapter, well complete our discussion of building desktop applications by focusing on the objects that forms contain—in particular, controls and components, common dialogs, and menus.

5.1 Common Controls and Components

This section contains a summary of the controls and components defined in the System.Windows.Forms namespace. Components are classes derived from the Component class defined in the System.ComponentModel namespace. They may or may not provide a visual interface. They are often used as elements of forms but dont have to be. Controls are classes derived from the Control class defined in the System.Windows.Forms namespace. Controls generally are used to build the visual appearance of a form. The Control class itself is derived from the Component class, so controls are also components. The common dialog boxes are not listed here, even though they all derive from the Component class. They are given their own section, Sect ion 5.4 later in this chapter.

5.1.1 The Button Class

This class represents a button control, which is one of the most commonly used controls in Windows applications. The Button classs Click event, which it inherits from Control, is its most commonly used event. The Button class inherits two important properties from ButtonBase: FlatStyle and Image. The first determines the appearance of the button and can take any value of the FlatStyle enumeration: Flat , Popup , Standard the default, and System . Buttons with these four settings are shown in Figur e 5- 1 . Assigning FlatStyle.System as the value of the FlatStyle property makes the appearance of the button dependent on the operating system. Figure 5-1. Various appearances of the Button control The Image property allows you to embed an image into a button. The following code shows how to programmatically set the Image property of Button: Button1.Image = New System.Drawing.Bitmapfilepath

5.1.2 The CheckBox Class

The CheckBox class represents a checkbox control. Its appearance is determined by its Appearance property, which can take either value of the Appearance enumeration: Button or Normal the default. The Button value is rarely used because this setting makes the checkbox look like a Button control.