打印预览正常,但再打印就打印出空白纸,该怎么办呀?
原因我知道了,是一个记录当前页的变量在打印的时候没能重置为0。可是该在哪里重置呀,我就不知道了,还望各位大侠帮忙!我的代码:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
intCurrPage = 0
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim PrintFont, HeaderFont As Font
PrintFont = New Font("Microsoft Sans Serif", 14, FontStyle.Regular)
HeaderFont = New Font("Microsoft Sans Serif", 18, FontStyle.Bold)
Dim intPrintAreaHeight, intPrintAreaWidth, marginLeft, marginTop As Int32
With PrintDocument1.DefaultPageSettings
' Initialize local variables that contain the bounds of the printing
' area rectangle.
intPrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
intPrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
' Initialize local variables to hold margin values that will serve
' as the X and Y coordinates for the upper left corner of the printing
' area rectangle
marginLeft = .Margins.Left ' X coordinate
marginTop = .Margins.Top ' Y coordinate
End With
' If the user selected Landscape mode, swap the printing area height
' and width.
If PrintDocument1.DefaultPageSettings.Landscape Then
Dim intTemp As Int32
intTemp = intPrintAreaHeight
intPrintAreaHeight = intPrintAreaWidth
intPrintAreaWidth = intTemp
End If
Dim intScale As Int32
Dim Yaxis As Int32
intScale = 380
Dim i As Int32
Dim j As Int32
Dim currRowPix As Int32
Dim DataCurrRow As Int32
j = 0
On Error Resume Next
For i = 1 To 6
DataCurrRow = intCurrPage * 6 + i - 1
If DataCurrRow < RsCount Then
myRow = myTable.Rows(DataCurrRow)
currRowPix = i - j - 1
Yaxis = currRowPix * intScale
If i Mod 2 = 1 Then
e.Graphics.DrawString(myRow.Item("TITLE"), HeaderFont, Brushes.Black, 180, Yaxis + 10, New StringFormat)
e.Graphics.DrawString("Lable", PrintFont, Brushes.Black, 180, Yaxis + 55, New StringFormat)
e.Graphics.DrawString("Orleans Box #:" & myRow.Item("BOX_CODE"), PrintFont, Brushes.Black, 20, Yaxis + 100, New StringFormat)
e.Graphics.DrawString("Department:" & myRow.Item("DEPARTMENT"), PrintFont, Brushes.Black, 20, Yaxis + 130, New StringFormat)
e.Graphics.DrawString("Entry Date:" & myRow.Item("IN_DATE"), PrintFont, Brushes.Black, 20, Yaxis + 160, New StringFormat)
e.Graphics.DrawString("BURN Date:" & myRow.Item("DEST_DATE"), PrintFont, Brushes.Black, 20, Yaxis + 190, New StringFormat)
e.Graphics.DrawString("Material Dates:" & myRow.Item("FROM_DATE") & " TO " & myRow.Item("TO_DATE"), PrintFont, Brushes.Black, 20, Yaxis + 220, New StringFormat)
e.Graphics.DrawString("Bar Code Number:" & myRow.Item("BAR_CODE"), PrintFont, Brushes.Black, 20, Yaxis + 250, New StringFormat)
j = j + 1
Else
e.Graphics.DrawString(myRow.Item("TITLE"), HeaderFont, Brushes.Black, 580, Yaxis + 10, New StringFormat)
e.Graphics.DrawString("Lable", PrintFont, Brushes.Black, 580, Yaxis + 55, New StringFormat)
e.Graphics.DrawString("Orleans Box #:" & myRow.Item("BOX_CODE"), PrintFont, Brushes.Black, 460, Yaxis + 100, New StringFormat)
e.Graphics.DrawString("Department:" & myRow.Item("DEPARTMENT"), PrintFont, Brushes.Black, 460, Yaxis + 130, New StringFormat)
e.Graphics.DrawString("Entry Date:" & myRow.Item("IN_DATE"), PrintFont, Brushes.Black, 460, Yaxis + 160, New StringFormat)
e.Graphics.DrawString("BURN Date:" & myRow.Item("DEST_DATE"), PrintFont, Brushes.Black, 460, Yaxis + 190, New StringFormat)
e.Graphics.DrawString("Material Dates:" & myRow.Item("FROM_DATE") & " TO " & myRow.Item("TO_DATE"), PrintFont, Brushes.Black, 460, Yaxis + 220, New StringFormat)
e.Graphics.DrawString("Bar Code Number:" & myRow.Item("BAR_CODE"), PrintFont, Brushes.Black, 460, Yaxis + 250, New StringFormat)
End If
If (intCurrPage + 1) * 6 < RsCount Then e.HasMorePages = True
End If
Next
intCurrPage = intCurrPage + 1
End Sub