1. Use code similar to the following:
// Print the table.
private void textPrintDocument_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
// Make some data.
Student[] students =
{
new Student() {FirstName=”Ann”, LastName=”Archer”,
TestScores=new int[] {91, 92, 93, 94}},
new Student() {FirstName=”Bob”, LastName=”Blarth”,
TestScores=new int[] {81, 82, 83, 84}},
new Student() {FirstName=”Cyd”, LastName=”Carter”,
TestScores=new int[] {71, 72, 73, 74}},
new Student() {FirstName=”Dan”, LastName=”Deever”,
TestScores=new int[] {61, 62, 63, 64}},
};
// Get the coordinates for the rst row and the columns.
int y = e.MarginBounds.Top;
int x0 = e.MarginBounds.Left;
int x1 = x0 + 200;
int x2 = x1 + 100;
int x3 = x2 + 100;
int x4 = x3 + 100;
// Make a font to use.
using (Font font = new Font(“Times New Roman”, 20))
{
// Draw column headers.
e.Graphics.DrawString(“Name”, font, Brushes.Black, x0, y);
e.Graphics.DrawString(“Test 1”, font, Brushes.Black, x1, y);
e.Graphics.DrawString(“Test 2”, font, Brushes.Black, x2, y);
e.Graphics.DrawString(“Test 3”, font, Brushes.Black, x3, y);
e.Graphics.DrawString(“Test 4”, font, Brushes.Black, x4, y);
// Move Y down for the rst row.
y += 30;
// Loop through the Students displaying their data.
foreach (Student student in students)
{
// Display the Student’s values.
e.Graphics.DrawString(student.FirstName + “ “ +
student.LastName, font, Brushes.Black, x0, y);
e.Graphics.DrawString(student.TestScores[0].ToString(),
font, Brushes.Black, x1, y);
e.Graphics.DrawString(student.TestScores[1].ToString(),
font, Brushes.Black, x2, y);
e.Graphics.DrawString(student.TestScores[2].ToString(),
font, Brushes.Black, x3, y);
e.Graphics.DrawString(student.TestScores[3].ToString(),
font, Brushes.Black, x4, y);
// Move Y down for the next row.
y += 30;
}
596906c31.indd 366 4/7/10 12:34:31 PM