首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

PrintDocument打印多页有关问题

2012-12-16 
PrintDocument打印多页问题Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System

PrintDocument打印多页问题


  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        pageCount = 0
        currePage = 0
        pageSize = 20

        orderPrintPreviewDialog.Document = orderPrintDocument
        orderPrintDocument.DefaultPageSettings.Landscape = True '    //横向打印

        AddHandler orderPrintDocument.PrintPage, AddressOf Me.orderPrintDocument_PrintPage
        orderPrintPreviewDialog.PrintPreviewControl.Zoom = 1.0
        orderPrintPreviewDialog.WindowState = FormWindowState.Normal

        pageCount = dt.Rows.Count / pageSize
        orderPrintPreviewDialog.ShowDialog()

    End Sub

    Dim currentPageIndex As Int32 = 0
    Dim rowCount As Int32 = 0
    ' Dim pageCount As Int32 = 0
    Dim flag As Boolean = False
    Private Sub orderPrintDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles orderPrintDocument.PrintPage

       

        Dim fntTxt As Font = New Font("宋体", 11, FontStyle.Regular)
        Dim brush As Brush = New SolidBrush(Color.Black)
        Dim pen As Pen = New Pen(Color.Black)
        pageCount = 3

        If (currentPageIndex = 0) Then
            e.Graphics.DrawString("111111111111111111111111111", fntTxt, brush, New Point(0, 0))
        ElseIf currentPageIndex = 1 Then
            e.Graphics.DrawString("222222222222222222222222222", fntTxt, brush, New Point(0, 0))
        ElseIf currentPageIndex = 2 Then
            e.Graphics.DrawString("333333333333333333333333333", fntTxt, brush, New Point(0, 0))
        End If

  

        currentPageIndex += 1
        If (currentPageIndex < pageCount) Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
            currentPageIndex = 0


            flag = True
            Exit Sub
        End If

  
    End Sub



打印是三页了,但问题是每一页的内容不正确,也就是每一页都把所有的内容打一次(原来设想是每一页打对应的内容),现在每一页上显示都是重叠内容的一行文字
[解决办法]
两个控件,PrintDocument与PrintPreviewDialog
[解决办法]
该回复于2011-04-21 09:01:35被版主删除
[解决办法]
事件搞错了,应该在OnPrintPage事件写吧
[解决办法]
看代码是可以的哦,呵呵
设个断点看看吧
[解决办法]
這一段造成的
currentPageIndex += 1
        If (currentPageIndex < pageCount) Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
            currentPageIndex = 0
            flag = True
            Exit Sub
        End If

-----------
所以要看看累加的 currentPageIndex 和 pageCount
且pageCount = 0 ,當然 1就跳頁了
[解决办法]
引用:
事件搞错了,应该在OnPrintPage事件写吧


vb.net PrintPage事件是对于要打印的每一页发生
没有OnPrintPage事件。。
[解决办法]
引用:
這一段造成的
currentPageIndex += 1
  If (currentPageIndex < pageCount) Then
  e.HasMorePages = True
  Else
  e.HasMorePages = False
  currentPageIndex = 0
  flag = True
  Exit Sub
  End If

-----……


这个能说清楚点吗。。。
调试:pageCount一直都是3
currentPageIndex 从0到2
之后进入
         Else
            e.HasMorePages = False
            currentPageIndex = 0
            flag = True
            Exit Sub
        End If

之后,又重新执行orderPrintDocument_PrintPage()这个方法。。一直执行了几次之后才退出。。
[解决办法]
就是执行了 e.HasMorePages = False
这句之后,却没有马上跳出这个方法,还是继续执行这个方法几次之后才中止
[解决办法]
我遇到的和你一个情况 现在解决了吗?
[解决办法]
currentPageIndex += 1
应该放在下面
If (currentPageIndex < pageCount) Then


    e.HasMorePages = True
    currentPageIndex += 1
Else

你原来的代码,第2页和第3页必然重合在一起.
先分页,再加页数统计你在3页之内的输出就应该正常了.
第4页如果存在的话,还是会和第3页印在一行上.

热点排行