繁体   English   中英

在vb.net中打印多页

[英]Print multiple pages in vb.net

如何打印多页? 在我的表单中,我有带有相应标签的文本框,例如。 (ID,名称,课程等),但问题是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

如果一页以上,则需要确保对每个需要打印的页面都调用一次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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM