如何打印具有100行

时间:2016-08-17 05:35:57

标签: vb.net datagridview

我试图打印一个包含7列和100行的数据网格。对于dat,我使用了位图。但它只打印多达55行,即只有1页打印页面,它不会生成多页打印。对不起,我的英语不好。请帮忙。

提前完成..

这是我的代码:

Private bitmap As Bitmap
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

    '************************RESIZE DATAGRID VIEW TO FULL SIZE **********************
    Dim height As Integer = DataGridView1.Height
    DataGridView1.Height = (DataGridView1.RowCount + 1) * DataGridView1.RowTemplate.Height

    '************************CREATE A BITMAP AND DRAW THE DATAGRID VIEW ON IT **********************************
    bitmap = New Bitmap(Me.DataGridView1.Width, Me.DataGridView1.Height)
    DataGridView1.DrawToBitmap(bitmap, New Rectangle(0, 0, Me.DataGridView1.Width, Me.DataGridView1.Height))

    '************************Resize datagrid view back to original size ********************************************
    DataGridView1.Height = height

    '********************* show the print preview ***********************************************************
    PrintPreviewDialog1.Document = PrintDocument1

    PrintPreviewDialog1.PrintPreviewControl.Zoom = 1

    PrintPreviewDialog1.ShowDialog()

End Sub

Private Sub PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    '********************************************* PRINT THE CONTENTS ************************************************************
    e.Graphics.DrawImage(bitmap, 0, 0)

End Sub   

1 个答案:

答案 0 :(得分:0)

  

PrintPageEventArgs

有一个名为

的属性
  

HasMorePages的

。您需要从datagridview高度中减去页面高度,并确定是否需要打印另一个页面。是的,然后你可以将它设置为true,它将再次运行sub。

Private Sub PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    '********************************************* PRINT THE CONTENTS ************************************************************
    e.Graphics.DrawImage(bitmap, 0, 0)

    Dim rectPrint As RectangleF = ev.PageSettings.PrintableArea
    ' changed this to width if printing in landscape mode
    If Me.DataGridView1.Height - rectPrint.Height > 0 Then e.HasMorePages = True

End Sub