Private printIndex As Integer 'The index of the listview item being printed.
Private majorFont As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point) 'The font used to print large text.
Private minorFont As New Font("Arial", 7, FontStyle.Regular, GraphicsUnit.Point) 'The font used to print small text.
'...
Private Sub printButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printButton.Click
'Reset the print index.
Me.printIndex = 0
If Me.printDialogue.ShowDialog() = DialogResult.OK Then
#If DEBUG Then
'Display a print preview.
Me.printPreviewDialogue.WindowState = FormWindowState.Maximized
Me.printPreviewDialogue.ShowDialog()
#Else
'Print the mail-outs directly.
Me.printDocument.Print()
#End If
End If
End Sub
Private Sub printDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printDocument.PrintPage
Dim customerItem As ListViewItem
Dim customerName, customerAddress As String
'Print three customers per page.
For i As Integer = 0 To 2
If Me.printIndex >= Me.vipListView.CheckedItems.Count Then
'Reset the print index in case this was a preview.
Me.printIndex = 0
e.HasMorePages = False
Exit For
End If
customerItem = Me.vipListView.CheckedItems(Me.printIndex)
'Build the customer name starting with the salutation.
customerName = customerItem.SubItems(3).Text
If customerItem.SubItems(4).Text <> "" Then
If customerName <> "" Then
customerName += " "
End If
'Add the given names.
customerName += customerItem.SubItems(4).Text
End If
If customerItem.SubItems(5).Text <> "" Then
If customerName <> "" Then
customerName += " "
End If
'Add the surname.
customerName += customerItem.SubItems(5).Text
End If
'Build the customer address starting with the number and street.
customerAddress = customerItem.SubItems(6).Text.Replace(",", vbNewLine)
If customerItem.SubItems(7).Text <> "" Then
If customerAddress <> "" Then
customerAddress += vbNewLine
End If
'Add the suburb.
customerAddress += customerItem.SubItems(7).Text
End If
If customerItem.SubItems(8).Text <> "" Then
If customerAddress <> "" Then
customerAddress += vbNewLine
End If
'Add the state.
customerAddress += customerItem.SubItems(8).Text
If customerItem.SubItems(9).Text <> "" Then
If customerAddress <> "" Then
customerAddress += ", "
End If
'Add the postcode.
customerAddress += customerItem.SubItems(9).Text
End If
Else
If customerItem.SubItems(9).Text <> "" Then
If customerAddress <> "" Then
customerAddress += vbNewLine
End If
'Add the postcode.
customerAddress += customerItem.SubItems(9).Text
End If
End If
If customerItem.SubItems(10).Text <> "" Then
If customerAddress <> "" Then
customerAddress += vbNewLine
End If
'Add the country.
customerAddress += customerItem.SubItems(10).Text
End If
e.Graphics.DrawString(String.Format("{0}{1}{2}", customerName, vbNewLine, customerAddress), Me.majorFont, Brushes.Black, 130, i * 390 + 240)
Dim vipPointsCount As Integer = Integer.Parse(customerItem.SubItems(2).Text)
If vipPointsCount > 0 Then
e.Graphics.DrawString(String.Format("Dear Customer,{0}As at {1} you have accumulated VIP points to the value of {2},{0}which can be redeemed on any items currently in stock.{0}Please read the conditions of use relating to VIP points.", _
vbNewLine, _
Date.Today.ToShortDateString(), _
FormatCurrency(vipPointsCount * Globals.Options.PointsRedeemedValue, 0)), _
Me.majorFont, _
Brushes.Black, _
130, _
i * 390 + 110)
e.Graphics.DrawString(Me.CONDITIONSOFUSE, _
Me.minorFont, _
Brushes.Black, _
500, _
i * 390 + 190)
End If
e.HasMorePages = True
Me.printIndex += 1
Next
End Sub