我正在从VB5转换,我试图在VB.NET中获得相同的printer.NewPage。 我的代码如下所示,但它只是在一个页面上打印两行。 该程序打印两页计算结果(数组等),它不读取和打印文件。 我如何获得第二页?
Private Sub PrintGeneralReport()
Dim PrintPreviewSelected As Boolean = True
'Set the doc to print
Dim pDoc As New PrintDocument
pDoc.PrintController = New StandardPrintController 'turns off the printing page x of y dialog
'Get the printer to use
If Me.PrintDialog1.ShowDialog() = DialogResult.OK Then
pDoc.PrinterSettings.PrinterName = Me.PrintDialog1.PrinterSettings.PrinterName
'pDoc.DefaultPageSettings.Margins = New Margins(75, 50, 50, 50)
pDoc.DefaultPageSettings.Margins = New Margins(40, 10, 10, 10)
pDoc.OriginAtMargins = True
Else
pDoc = Nothing
Exit Sub
End If
' Install the PrintPage event handler.
AddHandler pDoc.PrintPage, AddressOf PrintGenReport
If PrintPreviewSelected Then
''print preview
PrintPreviewDialog1.Document = pDoc
PrintPreviewDialog1.UseAntiAlias = True
PrintPreviewDialog1.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()
Else
'just print
pDoc.Print()
End If
RemoveHandler pDoc.PrintPage, AddressOf PrintGenReport
End Sub
Private Sub PrintGenReport(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim fnt10 As Font = New Font("Courier New", 10, FontStyle.Regular)
e.Graphics.DrawString("Page 1", fnt10, Brushes.Black, 20, 100)
'ROARK1.Print_GeneralReportRK(Me, e)
e.HasMorePages = True
e.Graphics.DrawString("Page 2", fnt10, Brushes.Black, 20, 200)
'ROARK1.Print_MemberActions(e)
e.HasMorePages = False
End Sub
答案 0 :(得分:0)
试试这个:
Private PageNum As Integer = 1
Private Sub PrintGenReport(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
Dim fnt10 As Font = New Font("Courier New", 10, FontStyle.Regular)
e.Graphics.DrawString("Page " & PageNum.ToString(), fnt10, Brushes.Black, 20, 100 * PageNum)
e.HasMorePages = (PageNum < 2)
PageNum += 1
End Sub
注意PageNum
变量是在类级别定义的。您还应该在PrintGeneralReport()
方法中添加一行,以便在每个打印作业开始时将其设置回1
。