我想解决这个问题

时间:2021-08-01 11:50:51

标签: vb.net printing

打印

当我使用 for 循环打印数据库表并且该数据有两页时,我使用 e.hasmorepages=true。但 e.hasmorepages 并没有停止。手段继续。 代码如下:

Dim x As Int32 = e.MarginBounds.Left

    Dim y As Int32 = e.MarginBounds.Top
    Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
    fmt.LineAlignment = StringAlignment.Center
    fmt.Alignment = StringAlignment.Center
    Dim rec As Rectangle
    Dim mrow As Integer = 0
    Dim h As Int32 = 0
    Dim i As Int32
    If newpage Then
        'Dim image As Image
        'e.Graphics.DrawImage(image, 20, 20, 70, 50)
        

    End If
    For i = mrow To tbl.Rows.Count - 1
        x = e.MarginBounds.Left
        h = 0
        x = e.MarginBounds.Left
        For j As Integer = 0 To tbl.Columns.Count - 1
            rec = New Rectangle(x, y, 60, 30)
            e.Graphics.DrawRectangle(Pens.Black, rec)
            e.Graphics.DrawString(tbl.Rows(i)(j).ToString, rfont, Brushes.Black, rec, fmt)
            x += rec.Width
            h = Math.Max(h, rec.Height)
        Next
        y += h
        mrow += 1
        If y + h > e.MarginBounds.Bottom Then
            e.HasMorePages = True
            'mrow -= 1
            newpage = True
            Return
        Else
            newpage = False
        End If
    


    Next`

我搜索了很多博客,但这个问题没有解决。

0 个答案:

没有答案