在 VS 2010 上的 VB 中在多页上打印 [英] Print on multiple page in VB on VS 2010
本文介绍了在 VS 2010 上的 VB 中在多页上打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当数据网格视图的所有行超过底部边距时,我在将数据网格视图的所有行打印到另一页时遇到问题.当我点击打印预览时,它会不停地添加页面......这是我的代码.
Im having problem when printing all rows of data grid view into another page when it exceed the bottom margin. When i click print preview it will keep adding pages non stop.. Here is my code.
Dim mRow As Integer = 0
Dim newpage As Boolean = True
With dgvItems
Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
fmt.LineAlignment = StringAlignment.Center
fmt.Trimming = StringTrimming.EllipsisCharacter
Dim y As Single = a + 20
Do While mRow < .RowCount
Dim row As DataGridViewRow = .Rows(mRow)
Dim x As Single = e.MarginBounds.Left
Dim h As Single = 0
For Each cell As DataGridViewCell In row.Cells
Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, 70)
e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height)
If (newpage) Then
e.Graphics.DrawString(dgvItems.Columns(cell.ColumnIndex).HeaderText, .Font, Brushes.Black, rc, fmt)
Else
e.Graphics.DrawString(dgvItems.Rows(cell.RowIndex - 1).Cells(cell.ColumnIndex).FormattedValue.ToString(), .Font, Brushes.Black, rc, fmt)
End If
x += rc.Width
h = Math.Max(h, rc.Height)
Next
newpage = False
y += h
mRow += 1
If y + h > e.MarginBounds.Bottom Then
e.HasMorePages = True
mRow = 1
newpage = True
Exit Sub
End If
Loop
mRow = 0
End With
我也想问一下Visual Studio 2010中如何设置vb的页眉页脚,使页眉页脚可以在所有页面打印..
I would also like to ask about how to set the header and footer of vb in Visual studio 2010 so that the header and footer can be print in all pages..
推荐答案
希望对您有所帮助:
Private index As Integer
Private Sub Print(...) Handles PrintDocument1.PrintPage
Dim row As Integer = {some point you want to start at}
'Paint a title - since this event fires for each page
'continue loop or start loop
For i As Integer = index To myList.Count - 1
If Not row = e.MarginBounds.Bottom - 12 Then
'remember where we are in the list
index = i
'paint your contents
Else
'start new page
e.HasMorePages = True
Exit Sub
End If
Next
'reset the index for next print job
If Not e.HasMorePages Then index = 0
End Sub
这篇关于在 VS 2010 上的 VB 中在多页上打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文