locked
e.HasMorePages in VB.NET RRS feed

  • Question

  • Hallo!!!

    I have following code used in PrintDocument Action

            Dim PrintFont As New Font("Arial", 48, FontStyle.Bold, GraphicsUnit.Point)
            Dim StringToPrint As String = RichTextBox1.Text
            Dim numChars As Integer
            Dim numLines As Integer
            Dim stringForPage As String
            Dim strFormat As New StringFormat
            Dim rectDraw As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)
            Dim sizeMeasure As New SizeF(e.MarginBounds.Width, e.MarginBounds.Height - PrintFont.GetHeight(e.Graphics))
            strFormat.Trimming = StringTrimming.Word
            e.Graphics.MeasureString(StringToPrint, PrintFont, sizeMeasure, strFormat, numChars, numLines)
            stringForPage = StringToPrint.Substring(0, numChars)
            e.Graphics.DrawString(stringForPage, PrintFont, Brushes.Black, rectDraw, strFormat)
            If numChars < StringToPrint.Length Then
                StringToPrint = StringToPrint.Substring(numChars)
                e.HasMorePages = True
            Else
                e.HasMorePages = False
                StringToPrint = RichTextBox1.Text
            End If

    My problem is that so this code generates infinity looping of printing page one. It should generate few pages (when text is long), but I get only first page in infinity number. Does anybody knows where can be problem?

    Wednesday, December 4, 2013 3:51 PM

Answers