英文:
I have problems with print to next page
问题
以下是翻译的代码部分:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim Head As Integer = 0
Dim List As Integer
Head += 30
For List = 0 To ListView1.Items.Count - 1
Next
e.Graphics.DrawString("Pocket bok collection", New Drawing.Font("Times new roman", 20), Brushes.Black, 250, Head)
Head += 40
e.Graphics.DrawString("Pocket Serie Name", New Drawing.Font("Times new roman", 10), Brushes.Black, 50, Head)
e.Graphics.DrawString("Single/Double", New Drawing.Font("Times new roman", 10), Brushes.Black, 100, Head)
e.Graphics.DrawString("Pocket Nr", New Drawing.Font("Times new roman", 10), Brushes.Black, 200, Head)
e.Graphics.DrawString("Year", New Drawing.Font("Times new roman", 10), Brushes.Black, 300, Head)
e.Graphics.DrawString("Bought Date", New Drawing.Font("Times new roman", 10), Brushes.Black, 450, Head)
e.Graphics.DrawString("Cost", New Drawing.Font("Times new roman", 10), Brushes.Black, 550, Head)
List += 60
If List > 1000 Then
e.HasMorePages = True
End If
For Each Itm As ListViewItem In ListView1.Items
e.Graphics.DrawString(Itm.Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 50, List)
e.Graphics.DrawString(Itm.SubItems(1).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 100, List)
e.Graphics.DrawString(Itm.SubItems(2).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 200, List)
e.Graphics.DrawString(Itm.SubItems(3).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 300, List)
e.Graphics.DrawString(Itm.SubItems(4).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 450, List)
e.Graphics.DrawString(Itm.SubItems(5).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 550, List)
List += 50
Next
e.HasMorePages = False
Exit Sub
End Sub
希望这可以帮助你检查你的打印代码。如果仍然有问题,请提供更多详细信息,以便我可以帮助你解决它。
英文:
I get the first page to work but it does not print the next page, if I have more rows or if I space it out more to get it to print on the next print page it doesn't do that.
The code that I use.
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim Head As Integer = 0
Dim List As Integer
Head += 30
For List = 0 To ListView1.Items.Count - 1
Next
e.Graphics.DrawString("Pocket bok collection", New Drawing.Font("Times new roman", 20), Brushes.Black, 250, Head)
Head += 40
e.Graphics.DrawString("Pocket Serie Name", New Drawing.Font("Times new roman", 10), Brushes.Black, 50, Head)
e.Graphics.DrawString("Single/Double", New Drawing.Font("Times new roman", 10), Brushes.Black, 100, Head)
e.Graphics.DrawString("Pocket Nr", New Drawing.Font("Times new roman", 10), Brushes.Black, 200, Head)
e.Graphics.DrawString("Year", New Drawing.Font("Times new roman", 10), Brushes.Black, 300, Head)
e.Graphics.DrawString("Bought Date", New Drawing.Font("Times new roman", 10), Brushes.Black, 450, Head)
e.Graphics.DrawString("Cost", New Drawing.Font("Times new roman", 10), Brushes.Black, 550, Head)
List += 60
If List > 1000 Then
e.HasMorePages = True
End If
For Each Itm As ListViewItem In ListView1.Items
e.Graphics.DrawString(Itm.Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 50, List)
e.Graphics.DrawString(Itm.SubItems(1).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 100, List)
e.Graphics.DrawString(Itm.SubItems(2).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 200, List)
e.Graphics.DrawString(Itm.SubItems(3).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 300, List)
e.Graphics.DrawString(Itm.SubItems(4).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 450, List)
e.Graphics.DrawString(Itm.SubItems(5).Text, New Drawing.Font("Times new roman", 10), Brushes.Black, 550, List)
List += 50
Next
e.HasMorePages = False
Exit Sub
End Sub
What am i missing or is something not right, i have search and watched but can't find why it is not working.
答案1
得分: 2
你在方法的最后无论发生什么情况都将e.HasMorePages
设置为False
,因此它永远不会打印第二页。如果你在提问之前进行了调试,就会注意到这一点。
e.HasMorePages
默认为False
,只有在有更多数据需要打印时才应将其设置为True
。你有一个If
块来执行这个操作。你的代码仍然存在其他问题,但这将解决你在这里提出的直接问题。
英文:
You're setting e.HasMorePages
to False
at the end of the method no matter what happens, so it will never print a second page. You would have seen that if you had debugged your code, as you are required to do before asking a question.
e.HasMorePages
is False
by default and you should set it to True
if and only if there is more data to print. You have an If
block to do that. There are still other issues with your code but that will address the immediate issue you have asked about here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论