除非我重新加载表格,否则当我移动到新记录时打印作业从中间或我离开的地方开始

Print job is starting in the middle or where I left off when I move to a new record unless I reload the form

去年我一直在学习编码。这个问题可能已经回答了,但我似乎无法将写组合串起来 google 答案。

我正在尝试从 windows 表单打印一组多页表单。想想我所在组织的每位员工当年的公开注册表格。我可以打印所有表格,但是当我移动到下一条记录时,打印作业似乎从 e.hasmorepages=false 停止的地方开始。我得到一个空白页。根据他们的选择,我有一些组合。如果下一条记录碰巧有不同的组合,它打印得很好。当它回到已经打印的组合之一时,我得到了空白页。就像打印子没有完全退出一样。

我在我的代码中的多个位置尝试了“Exit Sub”和“Return”。似乎没有任何效果。 我在下面发布了一些代码,知道这是非常简短的,因为我的实际代码大约有 15,000 行长。

      Imports System.Drawing.Printing
    
        Public Class PrintOEForms
        Dim PrintAll As Integer = 0
            Dim Print1 As Integer = 0
    
    Private Sub cmdPrintDocs_Click(sender As Object, e As EventArgs) Handles cmdPrintDocs.Click
    
        If cbUpdate911.Checked = True AndAlso cbUpdateCheckRel.Checked = True AndAlso cbUpdateW4.Checked = True AndAlso cbOE22.Checked = True AndAlso cbNoIns.Checked = True Then
                    PrintDocAll.DefaultPageSettings.Margins = New Printing.Margins(50, 50, 50, 50)
                    PrintDialog1.Document = PrintDocAll
                    If PrintDialog1.ShowDialog() = DialogResult.OK Then
                        PrintDocAll.Print()
    ****'I've tried "Exit Sub" and "Return" here****  
                    End If
    
    
                    PrintDialog2.Document = PrintDocAll                
                End If
    
    If cbUpdate911.Checked = True AndAlso cbUpdateCheckRel.Checked = True AndAlso cbUpdateW4.Checked = True AndAlso cbOE22.Checked = True AndAlso cbNoIns.Checked = True Then
                    PrintDoc1.DefaultPageSettings.Margins = New Printing.Margins(50, 50, 50, 50)
                    PrintDialog1.Document = PrintDoc1
                    If PrintDialog1.ShowDialog() = DialogResult.OK Then
                        PrintDoc1.Print()
                    End If
                    PrintDialog2.Document = PrintDoc1pdf               
                End If
    
    End Sub
    
    Private Sub PrintDocAll_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocAll.PrintPage
    
            Select Case PrintAll
                
                Case 0
                    'Confidential Cover Sheet
                    
                    e.HasMorePages = True
               
                Case 1
                    'Ins Options
                    e.Graphics.DrawImage(pbInsOptions.BackgroundImage, 50 + 15, 50 + 20)
                   
                    e.HasMorePages=True

               Case 2
                   'Ins Pg1
                   e.Graphics.DrawImage(pbIns1.Image, 13, 15)
                
                    e.HasMorePages = True
   

               Case 3
                   'Ins Pg2
                   e.grahics.DrawImage(pbIns2.Image, 13,15)
    
                   e.HasMorePages = True
    
            End Select

             PrintAll += 1
    End Sub
    
  Private Sub PrintDoc1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDoc1.PrintPage

        Select Case Print1
            
            Case 0
                'Confidential Cover Sheet
                
                e.HasMorePages = True
           
            Case 1
                'Ins Options
                e.Graphics.DrawImage(pbInsOptions.BackgroundImage, 50 + 15, 50 + 20)
               
            Case 2
                'Ins Pg1
                e.Graphics.DrawImage(pbIns1.Image, 13, 15)
                
                    e.HasMorePages = False  

    **'I've tried "Exit Sub" and "Return" here**  
            
          End Select
    
            Print1 += 1
        End Sub
    End Sub

您是否尝试过初始化 printDocument 对象?也许改变

    If cbUpdate911.Checked = True AndAlso cbUpdateCheckRel.Checked = True AndAlso cbUpdateW4.Checked = True AndAlso cbOE22.Checked = True AndAlso cbNoIns.Checked = True Then
                PrintDocAll.DefaultPageSettings.Margins = New Printing.Margins(50, 50, 50, 50)

进入:

    If cbUpdate911.Checked = True AndAlso cbUpdateCheckRel.Checked = True AndAlso cbUpdateW4.Checked = True AndAlso cbOE22.Checked = True AndAlso cbNoIns.Checked = True Then

                PrintDocAll = new PrintDocument
                PrintDocAll.DefaultPageSettings.Margins = New Printing.Margins(50, 50, 50, 50)

在以下过程中:

Private Sub PrintDocAll_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocAll.PrintPage

        Select Case PrintAll
            Case 0
            Case 1
           Case 2
           Case 3
               'Ins Pg2
               e.grahics.DrawImage(pbIns2.Image, 13,15)

               e.HasMorePages = True ' This should be = False 

        End Select

         PrintAll += 1
End Sub

在情况 3 中,将 e.HasMorePages 设置为 False。此外,在打印之前将 PrintAll 重置为零。

改变这个:

If PrintDialog1.ShowDialog() = DialogResult.OK Then
    PrintDocAll.Print()
End If

为此:

If PrintDialog1.ShowDialog() = DialogResult.OK Then
    PrintAll = 0
    PrintDocAll.Print()
End If

还有这个:

If PrintDialog1.ShowDialog() = DialogResult.OK Then
    PrintDoc1.Print()
End If

对此:

If PrintDialog1.ShowDialog() = DialogResult.OK Then
    Print1 = 0
    PrintDoc1.Print()
End If

否则这些值不会在每个文档后重置,您将在已经前进到序列末尾后开始下一个。