Byron

Byron

  • NA
  • 7
  • 0

VB .Net printing HasMorePages issues

May 11 2007 1:53 AM
I've been working on getting this print function to work all night. It prints single pages fine but on multi-pages it just prints over the original page like the page break isn't being sent. What drives me crazy is I've written print functions in VB.NET before... and this function works like my old code..

    Private LineCount As Integer = 0
    Private Page As Int32 = 1
    Private Sub PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles pDoc.PrintPage
        Dim seps As String() = {vbNewLine}
        Dim LineOn As Integer = 0

        Try
            Dim f As New Font("Lucida Console", 9.75)

            Dim x As Single = e.MarginBounds.Left / 2
            Dim y As Single = e.MarginBounds.Top / 2
            Dim width As Single = e.PageBounds.Width - x
            Dim height As Single = e.PageBounds.Height - y


            e.Graphics.DrawString(title, f, Brushes.Black, x, y - 2)
            y += 14.625

            e.Graphics.DrawLine(Pens.Black, x, y, width - x, y)
            e.Graphics.DrawLine(Pens.Black, x, height - 38, width - x, height - 38)
            e.Graphics.DrawString("Page " + Trim(Page.ToString), f, Brushes.Black, x, height - 33)

            y += 9.75
            x *= 1.5

            For Each t As String In txt.Split(seps, StringSplitOptions.None)

                Dim h As String = t
                Dim l As Int32 = 75

                'allow inital newline
                Dim nl As Boolean = True

                While (h <> "" Or nl)
                    nl = False

                    If y > height - 50 Then
                        LineCount = LineOn
                        Page += 1
                        e.HasMorePages = True
                        Exit Sub
                    End If

                    If h.Length > l Then
                        t = h.Substring(0, l)
                        h = vbTab + h.Substring(l, h.Length - l)
                        l = 69
                    Else
t = h h = "" End If If LineOn >= LineCount Then e.Graphics.DrawString(t, f, Brushes.Black, x, y) y += 14.625 End If LineOn += 1 End While Next LineCount = 0 Page = 1 e.HasMorePages = False Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "cPrinter: PrintPage()") End Try End Sub