PrintDocument打印多页有关问题
PrintDocument打印多页问题
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
pageCount = 0
currePage = 0
pageSize = 20
orderPrintPreviewDialog.Document = orderPrintDocument
orderPrintDocument.DefaultPageSettings.Landscape = True ' //横向打印
AddHandler orderPrintDocument.PrintPage, AddressOf Me.orderPrintDocument_PrintPage
orderPrintPreviewDialog.PrintPreviewControl.Zoom = 1.0
orderPrintPreviewDialog.WindowState = FormWindowState.Normal
pageCount = dt.Rows.Count / pageSize
orderPrintPreviewDialog.ShowDialog()
End Sub
Dim currentPageIndex As Int32 = 0
Dim rowCount As Int32 = 0
' Dim pageCount As Int32 = 0
Dim flag As Boolean = False
Private Sub orderPrintDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles orderPrintDocument.PrintPage
Dim fntTxt As Font = New Font("宋体", 11, FontStyle.Regular)
Dim brush As Brush = New SolidBrush(Color.Black)
Dim pen As Pen = New Pen(Color.Black)
pageCount = 3
If (currentPageIndex = 0) Then
e.Graphics.DrawString("111111111111111111111111111", fntTxt, brush, New Point(0, 0))
ElseIf currentPageIndex = 1 Then
e.Graphics.DrawString("222222222222222222222222222", fntTxt, brush, New Point(0, 0))
ElseIf currentPageIndex = 2 Then
e.Graphics.DrawString("333333333333333333333333333", fntTxt, brush, New Point(0, 0))
End If
currentPageIndex += 1
If (currentPageIndex < pageCount) Then
e.HasMorePages = True
Else
e.HasMorePages = False
currentPageIndex = 0