
TRY IT
In this Try It, you build a program that prints and displays a preview of the table shown in
Figure 31-2. You build an array of
Student objects and then loop through them displaying
their values as shown in the figure.
FIGURE 312
You can download the code and resources for this Try It from the book’s web
page at
www.wrox.com or www.CSharpHelper.com/24hour.html. You can find
them in the Lesson31 folder of the download.
Lesson Requirements
Start a new project and create the program’s main form. Add
PrintDocument and
PrintPreviewDialog components to do the printing and previewing.
Add appropriate event handlers to the Preview and Print buttons.
Add a
Student class with FirstName and LastName properties. Also give it a TestScores
property that is an array of integers.
Create the
PrintPage event handler.
Create an array of
Student objects. Initialize them using array and object initializers.
Loop through the
Student objects printing them using code similar to the code used
by the PrintText example program described earlier.
Draw a rectangle around the table.
596906c31.indd 364 4/7/10 12:34:31 PM