【问题标题】:Print multiple pages in vb.net在 vb.net 中打印多页
【发布时间】:2015-12-07 13:13:43
【问题描述】:

如何打印多页?在我的表单中,我有带有相应标签的文本框,例如。 (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

【问题讨论】:

标签: vb.net printing printdocument


【解决方案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

【讨论】:

  • 嗨,joel,谢谢你的回答,但我有一个好处,你能用我的代码给我看一个例子吗?谢谢你
  • 谢谢你!我真的很感谢你的帮助:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-07
  • 1970-01-01
  • 2013-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多