关于打印预览,来看看啊,会者不难,难者不会
--------------------编程问答--------------------Dim i As Integer = 1--------------------编程问答-------------------- 你的代码看起来没有问题,我试过了,可以正常打印出页码,嗯。我是用预览的
Dim TotalPageForPrint As Integer
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
PreviewPrt(e.Graphics, i) '绘制过程
i += 1
If i <= TotalPageForPrint Then
e.HasMorePages = True
Else
e.HasMorePages = False
i = 1
End If
End Sub
Dim currentPageIndex As Integer = 0--------------------编程问答-------------------- 后来我研究,觉得是因为我的代码写在了一个dlg 继承 printpreviwdlg的类里的
Dim pageCount = 5
Private Sub printDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim tpStr As String = "当前的页码是" & (currentPageIndex + 1).ToString
e.Graphics.DrawString(tpStr, Me.Font, Brushes.Blue, 200, 300)
If currentPageIndex <= pageCount Then
e.HasMorePages = True
currentPageIndex += 1
Else
e.HasMorePages = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintPreviewDialog1.ShowDialog()
End Sub
估计是这样导致程序会 被多调用一次
补充:.NET技术 , VB.NET