vb.net Code:
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim x As Integer
e.HasMorePages = True
Try
Dim Font1 As New System.Drawing.Font("Verdana", 20, FontStyle.Italic)
Dim Font2 As New System.Drawing.Font("Verdana", 12, FontStyle.Italic)
Dim yPos As Long = 190
Dim xPos As Long = 50
e.Graphics.DrawString("DATI TRENO " & infotreno1, Font1, Brushes.Black, 50, 50)
e.Graphics.DrawString("STAZIONE DI " & ComboBox1.SelectedValue, Font2, Brushes.Black, 50, 90)
e.Graphics.DrawString(paxinsalita1 & " CLIENTI IN SALITA", Font2, Brushes.Black, 50, 110)
e.Graphics.DrawString(paxindiscesa1 & " CLIENTI IN DISCESA", Font2, Brushes.Black, 50, 130)
e.Graphics.DrawString("DESTINAZIONI IN SALITA DA " & ComboBox1.SelectedValue, Font2, Brushes.Black, 50, 170)
For x = 0 To ListBox1.Items.Count - 1
e.Graphics.DrawString(ListBox1.Items(x).ToString, Font2, Brushes.Black, xPos, yPos, New StringFormat())
yPos = yPos + Font2.Height
Next
e.Graphics.DrawString("", Font2, Brushes.Black, xPos, yPos)
yPos = yPos + Font2.Height
e.Graphics.DrawString("DATI PRENOTAZIONI", Font2, Brushes.Black, xPos, yPos)
yPos = yPos + Font2.Height
For x = 0 To ListBox11.Items.Count - 1
e.Graphics.DrawString(ListBox11.Items(x).ToString, Font2, Brushes.Black, xPos, yPos, New StringFormat())
yPos = yPos + Font2.Height
Next
If x = ListBox11.Items.Count Then
e.HasMorePages = False
End If
Catch ex As Exception
MessageBox.Show(ex.Message & Environment.NewLine & ex.StackTrace)
End Try
End Sub