Private Sub mnuReportsCars_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuReportsCars.Click
' Create a report containing each car and its mileage
Try
Me.PrintPreviewDialog1.Document = Me.CarPrintDocument
Me.PrintPreviewDialog1.ShowDialog()
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub
Private Sub CarPrintDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles CarPrintDocument.PrintPage
Dim font_style As FontStyle = FontStyle.Bold Or FontStyle.Italic
Dim fontHeader As New Font("Times New Roman", 20, font_style)
Dim fontText As New Font("Arial", 12, FontStyle.Regular)
Dim y As Single = 10
Dim gr As Graphics = Me.CreateGraphics
Dim myItem As String
Dim myString As String
' Print the Header
e.Graphics.DrawString("Car Mileage Report", fontHeader, Brushes.Black, 300, y)
y += fontHeader.GetHeight(gr) + fontText.GetHeight(gr)
' Get the items in the Comboboxes
For Each carItem In cboCars.Items
carString &= carItem & ","
Next
Dim carArray() As String = Split(carString, ",")
'Print the Items
For x As Integer = 0 To carArray.Length - 2 ' It is 2 because the way it is built there is always a comma at the end with no further data
e.Graphics.DrawString(carArray(x).ToString , fontText, Brushes.Black, 300, y)
y += fontText.GetHeight(gr)
Next
End Sub