【发布时间】:2015-07-31 08:19:28
【问题描述】:
我想从 datagridview 打印数据, 但是,当数据超过一页时,它就会丢失。我尝试使用 e.HasMorePages 打印多页。我尝试搜索 3 小时前的示例,但不幸的是它不起作用
现在当我点击打印时,它只打印同一页而不停止。
请帮忙。
Private Sub PrintColorConsumption_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintColorConsumption.PrintPage
Dim x As Integer = 100
Dim y As Integer = 25
Dim header As Boolean = True
'draw headers
Dim j As Integer = 0
Do While (j < Me.DataGridView3.Columns.Count)
Dim rect As Rectangle = New Rectangle(x, y, Me.DataGridView3.Columns(j).Width, Me.DataGridView3.ColumnHeadersHeight)
Dim sf As StringFormat = New StringFormat
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center
e.Graphics.FillRectangle(Brushes.LightGray, rect)
e.Graphics.DrawRectangle(Pens.Black, rect)
If (Not (Me.DataGridView3.Columns(j).HeaderText) Is Nothing) Then
e.Graphics.DrawString(Me.DataGridView3.Columns(j).HeaderText, SystemFonts.DefaultFont, Brushes.Black, rect, sf)
End If
x = (x + rect.Width)
j = (j + 1)
Loop
x = 100
y = (y + Me.DataGridView3.ColumnHeadersHeight)
'draw rows
For Each row As DataGridViewRow In Me.DataGridView3.Rows
j = 0
Do While (j < Me.DataGridView3.Columns.Count)
Dim cell As DataGridViewCell
cell = row.Cells(j)
Dim rect As Rectangle = New Rectangle(x, y, cell.Size.Width, cell.Size.Height)
Dim sf As StringFormat = New StringFormat
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center
e.Graphics.DrawRectangle(Pens.Black, rect)
If (Not (cell.Value) Is Nothing) Then
e.Graphics.DrawString(cell.Value.ToString, SystemFonts.DefaultFont, Brushes.Black, rect, sf)
End If
x = (x + rect.Width)
j = (j + 1)
Loop
x = 100
y = (y + row.Height)
'----------------------New page----------------------------
If (y > e.MarginBounds.Bottom) Then 'Print new page
e.HasMorePages = True
y = 20
End If
'-----------------------------------------------------------------
Next
End Sub
【问题讨论】:
标签: vb.net printing datagridview