I'm trying to print a list of items in a listbox. I have 284 items. About a quarter of them get printed and the rest don't print and at the bottom the last entry is half way cutoff. I read online about keeping track of where you left off and printing to the next page by utilizing e.HasMorePages but nothing prints now and it just says its print page 1,2,3,4,5....etc. and nothing happens. I have to ctrl+c it and close program. How can I achieve desired print out?
Private Sub Print_Click(sender As Object, e As EventArgs) Handles Print.Click
Dim PrintDialog1 As New PrintDialog
Dim result As DialogResult = PrintDialog1.ShowDialog()
If result = DialogResult.OK Then PrintDocument1.Print()
' PrintPreviewDialog1.Document = PrintDocument1
' PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
' e.HasMorePages = True
Dim itemCount As Integer
Dim startX As Integer = 10
Dim startY As Integer = 10
Dim n As Integer
For x As Integer = 0 To SoftwareLBox.Items.Count - 1
e.Graphics.DrawString(SoftwareLBox.Items(x).ToString, SoftwareLBox.Font, Brushes.Black, startX, startY)
startY += SoftwareLBox.ItemHeight
If n = 150 Then
e.HasMorePages = True
n = 0
startY = 10
End If
startY += e.PageBounds.Height
n += 1
Next
End Sub
See Question&Answers more detail:os