打印预览正常,但再打印就打印出空白纸,该怎么办呀?

seethe 2005-07-07 08:35:39
原因我知道了,是一个记录当前页的变量在打印的时候没能重置为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
...全文
1807 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
seethe 2005-07-07
  • 打赏
  • 举报
回复
g555(g555) 回答的有道理,但并不完整,我修改了代码,现在可以使用,在此谢谢各位啦!!!
g555 2005-07-07
  • 打赏
  • 举报
回复
这句是继续打印
If (intCurrPage + 1) * 6 < RsCount Then e.HasMorePages = True

改成
If (intCurrPage + 1) * 6 < RsCount Then
e.HasMorePages = True
else
e.HasMorePages = false
intCurrPage=0
end if
zhouzh197895 2005-07-07
  • 打赏
  • 举报
回复
不知道是怎么写的,我也碰到过,预览后,页指针就指到最大页码了,再点击打印就从最大页+1,当然没数据了。
seethe 2005-07-07
  • 打赏
  • 举报
回复
UP
miaojx 2005-07-07
  • 打赏
  • 举报
回复
幫頂,別讓它沉阿
yikais 2005-07-07
  • 打赏
  • 举报
回复
没遇到过。UP
cansum396 2005-07-07
  • 打赏
  • 举报
回复
我也遇到过一个问题
预览时有数据
打印的时候只有格式
没有数据

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧