我有一个代码正在工作,它从 DataGridView 打印销售报告。代码打印良好,但当控制变量 I 的值超出可打印区域时,只能打印一页。我真的需要你的帮助。下面是代码。
Dim fntAddress As New Font("Comic Sans MS", 10, FontStyle.Regular)
Dim fntHeader As New Font("Calibri", 20, FontStyle.Bold)
Dim fntBodyText As New Font("Calibri", 12, FontStyle.Regular)
Dim fntHeaderText As New Font("Calibri", 13, FontStyle.Bold)
Dim strTotalSale = txtTotal.Text
e.Graphics.DrawString("SFC POINT OF SALE AND INVENTORY MANAGEMENT", fntHeader, Brushes.Black, 100, 0)
e.Graphics.DrawString("GENERATED SALES REPORT", New Font("Calibri", 18, FontStyle.Bold), Brushes.Black, 250, 30)
Dim strDateString As String = ""
If mtbStartDate.Text = " / /" Or mtbEndDate.Text = " / /" Then
strDateString = ""
ElseIf mtbStartDate.Text = mtbEndDate.Text Then
strDateString = "Report For Date Of : " & mtbStartDate.Text
ElseIf mtbStartDate.Text <> mtbEndDate.Text Then
strDateString = "Report For Dates Of : " & mtbStartDate.Text & " - " & mtbEndDate.Text
End If
e.Graphics.DrawString(strDateString, New Font("Courier New", 15, FontStyle.Regular), Brushes.Black, 5, 70)
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(5, 100, 770, 35))
e.Graphics.DrawString("Item Barcode", fntHeaderText, Brushes.Black, 10, 107)
e.Graphics.DrawString("Item Name", fntHeaderText, Brushes.Black, 160, 107)
e.Graphics.DrawString("Quantity", fntHeaderText, Brushes.Black, 360, 107)
e.Graphics.DrawString("Unit Cost", fntHeaderText, Brushes.Black, 450, 107)
e.Graphics.DrawString("Sub Total", fntHeaderText, Brushes.Black, 560, 107)
e.Graphics.DrawString("Date of Sale", fntHeaderText, Brushes.Black, 660, 107)
Dim RowCount As Integer = dgvSales.Rows.Count - 1
Static i As Integer = 139
Dim x1 = 10
Dim x2 = 700
Dim y1 = 155
Dim n As Integer = 0
While n < RowCount
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(5, i - 5, 770, 35))
e.Graphics.DrawString(dgvSales.Rows(n).Cells(0).Value, fntBodyText, Brushes.Black, 16, i)
e.Graphics.DrawString(dgvSales.Rows(n).Cells(1).Value, fntBodyText, Brushes.Black, 160, i)
e.Graphics.DrawString(dgvSales.Rows(n).Cells(2).Value, fntBodyText, Brushes.Black, 360, i)
e.Graphics.DrawString(dgvSales.Rows(n).Cells(3).Value, fntBodyText, Brushes.Black, 450, i)
e.Graphics.DrawString(dgvSales.Rows(n).Cells(4).Value, fntBodyText, Brushes.Black, 560, i)
e.Graphics.DrawString(dgvSales.Rows(n).Cells(5).Value, fntBodyText, Brushes.Black, 660, i)
i = i + 35
n = n + 1
End While
e.HasMorePages = False
e.Graphics.DrawLine(Pens.Black, 150, 100, 150, i - 5)
e.Graphics.DrawLine(Pens.Black, 350, 100, 350, i - 5)
e.Graphics.DrawLine(Pens.Black, 440, 100, 440, i - 5)
e.Graphics.DrawLine(Pens.Black, 550, 100, 550, i - 5)
e.Graphics.DrawLine(Pens.Black, 650, 100, 650, i - 5)
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(340, i + 40, 174, 50))
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(341, i + 41, 172, 48))
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(342, i + 42, 170, 46))
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(343, i + 43, 168, 44))
e.Graphics.DrawString("Total Sales.", New Font("Times New Roman (Headings CS)", 22, FontStyle.Bold), Brushes.Black, 341, i + 47)
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(525, i + 40, 250, 50))
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(526, i + 41, 248, 48))
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(527, i + 42, 246, 46))
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(528, i + 43, 244, 44))
e.Graphics.DrawString(strTotalSale, New Font("Times New Roman (Headings CS)", 23, FontStyle.Bold), Brushes.Black, 538, i + 47)