如何打印多个页面?在我的形式中,我有文本框及其相应的标签,例如。 (id,name,course等)但问题是1页不足以显示所有文本框。我必须添加另一个页面来显示其标签的剩余文本框。我试图将e.hasmorepages设置为true,但第二页中显示的文本框与第一页不同的文本框相同。
这是我的代码:
Private Sub printSisDoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printSisDoc.PrintPage
Dim labelFont As New Font("Arial", 11, FontStyle.Bold)
Dim textFont As New Font("Arial", 11, FontStyle.Regular)
Dim headerFont As New Font("Arial", 12, FontStyle.Bold)
e.Graphics.DrawString(lblGrade.Text, headerFont, Brushes.Black, 650, 660)
e.Graphics.DrawString(grade11.Text, textFont, Brushes.Black, 660, 690)
e.Graphics.DrawString(underline.Text, labelFont, Brushes.Black, 643, 692)
e.Graphics.DrawString(grade12.Text, textFont, Brushes.Black, 660, 715)
e.Graphics.DrawString(grade13.Text, textFont, Brushes.Black, 660, 740)
e.Graphics.DrawString(grade14.Text, textFont, Brushes.Black, 660, 765)
e.Graphics.DrawString(grade15.Text, textFont, Brushes.Black, 660, 790)
e.Graphics.DrawString(grade16.Text, textFont, Brushes.Black, 660, 815)
e.Graphics.DrawString(grade17.Text, textFont, Brushes.Black, 660, 840)
e.Graphics.DrawString(grade18.Text, textFont, Brushes.Black, 660, 865)
e.Graphics.DrawString(grade19.Text, textFont, Brushes.Black, 660, 890)
e.Graphics.DrawString(grade20.Text, textFont, Brushes.Black, 0, 1500)
mPageNumber += 1
e.HasMorePages = (mPageNumber <= 2)
End Sub
答案 0 :(得分:1)
如果您有多个页面,则需要确保为您需要打印的每个页面调用一次PrintPage()
方法。每次调用该方法时,都需要知道哪个页面是最新的以及应该写入该页面的内容。
e.HasMorePages
变量是PrintDocument
对象再次调用方法的方式。还要记住printSisDoc_PrintPage()
方法是类的一部分。您可以在类实例中设置数据,方法可以使用该实例来了解当前页面和要打印的内容。
Private Sub printSisDoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printSisDoc.PrintPage
Dim labelFont As New Font("Arial", 11, FontStyle.Bold)
Dim textFont As New Font("Arial", 11, FontStyle.Regular)
Dim headerFont As New Font("Arial", 12, FontStyle.Bold)
Select mPageNumber
Case 1
e.Graphics.DrawString(lblGrade.Text, headerFont, Brushes.Black, 650, 660)
e.Graphics.DrawString(grade11.Text, textFont, Brushes.Black, 660, 690)
e.Graphics.DrawString(underline.Text, labelFont, Brushes.Black, 643, 692)
e.Graphics.DrawString(grade12.Text, textFont, Brushes.Black, 660, 715)
e.Graphics.DrawString(grade13.Text, textFont, Brushes.Black, 660, 740)
e.Graphics.DrawString(grade14.Text, textFont, Brushes.Black, 660, 765)
e.Graphics.DrawString(grade15.Text, textFont, Brushes.Black, 660, 790)
e.Graphics.DrawString(grade16.Text, textFont, Brushes.Black, 660, 815)
e.Graphics.DrawString(grade17.Text, textFont, Brushes.Black, 660, 840)
e.Graphics.DrawString(grade18.Text, textFont, Brushes.Black, 660, 865)
e.Graphics.DrawString(grade19.Text, textFont, Brushes.Black, 660, 890)
e.HasMorePages = True
Case 2
e.Graphics.DrawString(grade20.Text, textFont, Brushes.Black, 0, 400)
e.HasMorePages = False
End Select
mPageNumber += 1
End Sub