【发布时间】:2015-11-10 02:58:33
【问题描述】:
我未能向我的打印机发出开始新页面的信号。在我设置 e.HasMorePages = True 后,它继续在第 1 页上打印。使用我的字体,我可以清晰地打印每页约 30 行,并且仍然保持边框
'print the text
'create a string array from the listView equipment items
Dim equip() As classReportObj
ReDim equip(0 To lstReport.Items.Count - 1)
For i = 0 To lstReport.Items.Count - 1
equip(i) =
New classReportObj() With {.name = lstReport.Items(i).Text, .type = lstReport.Items(i).SubItems(1).Text,
.completeTests = lstReport.Items(i).SubItems(2).Text, .incompleteTests = lstReport.Items(i).SubItems(3).Text,
.status = lstReport.Items(i).SubItems(4).Text}
Next i
'get the coordinates for the first row and the columns
Dim y As Integer = e.MarginBounds.Top
Dim x0 As Integer = e.MarginBounds.Left
Dim x1 As Integer = x0 + 150
Dim x2 As Integer = x1 + 150
Dim x3 As Integer = x2 + 150
Dim x4 As Integer = x3 + 120
Dim headerFont As New Font("Times New Roman", 10)
Dim maxLines As Integer 'maximum number of lines per page
maxLines = 30 '30 lines per page, including headers
Dim lineCount As Integer 'counts lines per printed page
'make a new font to use
Using theFont As New Font("Times New Roman", 10)
'draw the column headers
e.Graphics.DrawString("Project: " & project.name & " " & thisReportType & " Report, " & Now, theFont, Brushes.Black, x0, y)
e.Graphics.DrawString("Name", headerFont, Brushes.Black, x0, y + 30)
e.Graphics.DrawString("Type", headerFont, Brushes.Black, x1, y + 30)
e.Graphics.DrawString("Complete Tests", headerFont, Brushes.Black, x2, y + 30)
e.Graphics.DrawString("Incomplete Tests", headerFont, Brushes.Black, x3, y + 30)
e.Graphics.DrawString("Status", headerFont, Brushes.Black, x4, y + 30)
'mmove Y down for the next row
y += 60
Dim nameMax As Integer 'max characters for name
Dim typeMax As Integer 'max characters for type
'loop through each equipment to display the data
For Each aEquip In equip
'set the max character length for name and type
If aEquip.name.Length < 23 Then
nameMax = aEquip.name.Length
Else
nameMax = 23
End If
'
If aEquip.type.Length < 23 Then
typeMax = aEquip.type.Length
Else
typeMax = 23
End If
'display the equipment values
e.Graphics.DrawString(aEquip.name.Substring(0, nameMax), theFont, Brushes.Black, x0, y)
e.Graphics.DrawString(aEquip.type.Substring(0, typeMax), theFont, Brushes.Black, x1, y)
e.Graphics.DrawString(aEquip.completeTests, theFont, Brushes.Black, x2, y)
e.Graphics.DrawString(aEquip.incompleteTests, theFont, Brushes.Black, x3, y)
e.Graphics.DrawString(aEquip.status, theFont, Brushes.Black, x4, y)
'move Y down for the next row
y += 30
'increment the line counter for each piece of equipment
lineCount = lineCount + 1
'if we've reached the maximum number of lines per page
If (lineCount Mod maxLines) = 0 Then
'draw a box around it all
e.Graphics.DrawRectangle(Pens.Black, x0, e.MarginBounds.Top + 30, x4 - x0 + 100, y - e.MarginBounds.Top - 30)
e.HasMorePages = True 'But it doesn't start a new page, it continues printing page 1 unless I exit
Else
e.HasMorePages = False
End If
Next
End Using
'draw a box around it all
e.Graphics.DrawRectangle(Pens.Black, x0, e.MarginBounds.Top + 30, x4 - x0 + 100, y - e.MarginBounds.Top - 30)
'only printing one page (for now)
e.HasMorePages = False
End Sub
【问题讨论】: