我有一个打印模块,可以打印ListView中的所有数据。问题是它继续打印数据,直到它到达纸张的底部。这就是我添加e.Hasmorepage = true
的原因,但是当我尝试使用PrintPreviewControl
进行预览时,页数会不断增加。
应该只有2页
这是我的代码
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString("Material name", ReportFontL, Brushes.Black, 100, 220)
e.Graphics.DrawString("Price", ReportFontL, Brushes.Black, 500, 220)
e.Graphics.DrawString("Quantity", ReportFontL, Brushes.Black, 600, 220)
e.Graphics.DrawString("Total cost", ReportFontL, Brushes.Black, 700, 220)
Dim space As Integer = 240
For Each LV As ListViewItem In Mainform.ListViewMaterialUsed.Items
e.Graphics.DrawString(LV.Text, ReportFont, Brushes.Black, 100, space)
e.Graphics.DrawString(LV.SubItems(2).Text, ReportFont, Brushes.Black, 500, space)
e.Graphics.DrawString(LV.SubItems(1).Text, ReportFont, Brushes.Black, 600, space)
e.Graphics.DrawString(LV.SubItems(3).Text, ReportFont, Brushes.Black, 700, space)
space += 16
If (space > e.MarginBounds.Bottom) Then 'Print new page
e.HasMorePages = True
End If
Next
End Sub