首页 > 解决方案 > Hasmorepages 属性失败

问题描述

我创建了一个例程,旨在根据先前存储的行信息队列打印可变数量的行和/或页面。每页打印良好,但打印多页时,会叠印两页。我看不到我的逻辑错误,但一定有一个。有问题的代码副本如下。Nextline.newpage 是一个布尔值,设置为 true 以强制一个新页面。在我的文本示例中,有六个“Newpage”,“hasmorepages”设置为 true 六次,例程退出了六次。输出仍然是四页,其中一页打印正确,三页在一张纸上打印两页。任何帮助将不胜感激。顺便说一句,这是我的第一个问题,所以请客气。

Private Sub PrintLines(Sender As Object, e As PrintPageEventArgs) Handles PrintDoc.PrintPage
    Dim White As String = GetARGBString(PrinterDefaultBackcolor)
    Do Until Lines.Count = 0
        Dim Nextline As Lineformat = Lines.Dequeue
        If Nextline.NewPage Then
            e.HasMorePages = True
            Exit Sub
        End If
        With Nextline
            Dim LineBackColor As String = Nextline.backColor
            If LineBackColor <> White Or .Borders = True Then DrawShape(Nextline, e)
            If .Text <> "" Then DrawText(Nextline, e)
        End With
    Loop

End Sub

Private Sub DrawShape(Line As Lineformat, E As PrintPageEventArgs)
    With Line
        Dim Top As Integer = .Top * 100
        Dim Left As Integer = .Left * 100
        Dim Width As Integer = .BackGroundWidth * 100
        Dim Height As Integer = .BackGroundHeight * 100
        Dim Point As New Point(Left, Top)
        Dim Size As New Size(Width, Height)
        Dim Rect As New Rectangle(Point, Size)
        Dim TransparentFillColor As String = "00" & Strings.Right(.backColor, 6)
        Dim FillColor As FullColor = GetColorFromString(.backColor)
        Dim BorderPen As New Pen(Color.Black)
        Dim FillBrush As New SolidBrush(FillColor.Color)
        E.Graphics.FillRectangle(FillBrush, Rect)
        If Line.Borders = True Then
            E.Graphics.DrawRectangle(BorderPen, Rect)
        End If
    End With

End Sub
Private Sub DrawText(Line As Lineformat, E As PrintPageEventArgs)

    With Line
        Dim MyFont = SetFontStyle(.FontFamily, .FontPoints, .FontBold, .FontItalic, .FontUnderline)
        Dim TextColor As FullColor = GetColorFromString(.ForeColor)
        Dim MyBrush As New SolidBrush(TextColor.Color)
        Dim top As Integer = .Top * 100
        Dim Left As Integer = .Left * 100
        Dim Width As Integer = .LineWidth * 100
        Dim Height As Integer = .LineHeight * 100
        Dim point As New Point(Left, top)
        Dim Size As New Size(Width, Height)
        Dim Rect As New RectangleF(point, Size)
        Dim SF As New StringFormat()
        SF.FormatFlags = TextFormatFlags.WordEllipsis
        E.Graphics.DrawString(.Text, MyFont, MyBrush, Rect, SF)
    End With
End Sub

结束类

标签: vb.netvisual-studio-2012

解决方案


推荐阅读