Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 打印到下一页_Vb.net - Fatal编程技术网

Vb.net 打印到下一页

Vb.net 打印到下一页,vb.net,Vb.net,我读过很多关于在VB.NET中打印更多页面的帖子。然而,出于某种原因,我无法让它发挥作用。一旦I位置超过1000,我将e.hasmorepages设置为True。但是,它不是转到下一页,而是从顶部开始覆盖。我做错了什么?这是一个学校项目 Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage 'Decl

我读过很多关于在VB.NET中打印更多页面的帖子。然而,出于某种原因,我无法让它发挥作用。一旦I位置超过1000,我将e.hasmorepages设置为True。但是,它不是转到下一页,而是从顶部开始覆盖。我做错了什么?这是一个学校项目

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    'Declare variables for printing position, strings, and state name
    Dim yPos As Integer = 40
    Dim xPos As Integer = 25
    Dim strLine1 As String = String.Empty
    Dim strLine2 As String = String.Empty
    Dim strLine3 As String = String.Empty
    Dim strLine4 As String = String.Empty
    Dim strLine5 As String = String.Empty

    For i = 0 To (lstRecords.Items.Count - 1)
        'Concatenate strings for printing
        strLine1 = "Record Name: " & gVinyl(i).Name
        strLine2 = "Artist: " & gVinyl(i).Artist
        strLine3 = "Released: " & gVinyl(i).Year
        strLine4 = "Contains: " & gVinyl(i).Tracks.ToString & " tracks running " & gVinyl(i).Duration & " minutes"
        strLine5 = "Size: " & gVinyl(i).Size.ToString & " inches      Speed: " & gVinyl(i).Speed.ToString & " RPM"

        'Multiple page print
        If yPos > 1000 Then
            e.HasMorePages = True
            yPos = 40
        End If

        'Position each string line for printing
        e.Graphics.DrawString(strLine1, New Font("Times New Roman", 11), Brushes.Black, xPos, yPos)
        yPos += 20
        e.Graphics.DrawString(strLine2, New Font("Times New Roman", 11), Brushes.Black, xPos, yPos)
        yPos += 20
        e.Graphics.DrawString(strLine3, New Font("Times New Roman", 11), Brushes.Black, xPos, yPos)
        yPos += 20
        e.Graphics.DrawString(strLine4, New Font("Times New Roman", 11), Brushes.Black, xPos, yPos)
        yPos += 20
        e.Graphics.DrawString(strLine5, New Font("Times New Roman", 11), Brushes.Black, xPos, yPos)
        yPos += 50
    Next

    'Last page printed
    e.HasMorePages = False
End Sub
汉斯回答说:

您必须添加Exit Sub,以便它开始打印页面。然后事件再次激发以打印下一页。您不想再次从0开始。所以我要成为你们班的一员。使用BeginPrint事件将其设置为0


谢谢你,汉斯

您必须添加
Exit Sub
,以便它开始打印页面。然后事件再次激发以打印下一页。您不想再次从0开始。因此,将
i
作为类的字段。使用BeginPrint事件将其设置为0。哇,非常感谢您的帮助。我很高兴你没有编写代码,因为在深入研究之后,我能够理解你的意思。这真的很有帮助。万分感谢!!!