Vb.net 在VB中打印下一页

Vb.net 在VB中打印下一页,vb.net,Vb.net,我有一个打印模块,可以打印ListView中的所有数据。问题是,它会继续打印数据,直到数据到达纸的底部。这就是为什么我添加了e.Hasmorepage=true,但是当我尝试使用PrintPreviewControl预览它时,页数一直在增加 应该只有两页 这是我的密码 Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEv

我有一个打印模块,可以打印ListView中的所有数据。问题是,它会继续打印数据,直到数据到达纸的底部。这就是为什么我添加了
e.Hasmorepage=true
,但是当我尝试使用
PrintPreviewControl
预览它时,页数一直在增加

应该只有两页

这是我的密码

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    e.Graphics.DrawString("Material name", ReportFontL, Brushes.Black, 100, 220)
    e.Graphics.DrawString("Price", ReportFontL, Brushes.Black, 500, 220)
    e.Graphics.DrawString("Quantity", ReportFontL, Brushes.Black, 600, 220)
    e.Graphics.DrawString("Total cost", ReportFontL, Brushes.Black, 700, 220)

    Dim space As Integer = 240
    For Each LV As ListViewItem In Mainform.ListViewMaterialUsed.Items
        e.Graphics.DrawString(LV.Text, ReportFont, Brushes.Black, 100, space)
        e.Graphics.DrawString(LV.SubItems(2).Text, ReportFont, Brushes.Black, 500, space)
        e.Graphics.DrawString(LV.SubItems(1).Text, ReportFont, Brushes.Black, 600, space)
        e.Graphics.DrawString(LV.SubItems(3).Text, ReportFont, Brushes.Black, 700, space)
        space += 16
        If (space > e.MarginBounds.Bottom) Then       'Print new page
            e.HasMorePages = True
        End If
    Next

End Sub

也许我遗漏了什么,但是您在哪里设置生成预览文本?加载表单时,我有“PrintPreviewControl.Document=PrintDocument1”。您的循环不正确。它将打印listview项目的第一行,开始一个新页面,然后打印第一行,然后无限期地开始一个新页面。您需要使用一个
For n
循环,这样它就可以在我已经用于n的每个页面上恢复,但仍然相同。这是我的新for循环
对于Mainform.listViewMaterialAlused.Items.Count-1,索引为Integer=0的代码>可能我遗漏了什么,但是您在哪里设置生成预览文本?加载表单时,我有“PrintPreviewControl.Document=PrintDocument1”。您的循环不正确。它将打印listview项目的第一行,开始一个新页面,然后打印第一行,然后无限期地开始一个新页面。您需要使用一个
For n
循环,这样它就可以在我已经用于n的每个页面上恢复,但仍然相同。这是我的新for循环<代码>对于Mainform.listViewMaterialAlused.Items.Count-1,索引为整数=0