|
■No61120 (魔界の仮面弁士 さん) の方法に欠点があるのか分からないですが
ちょっと変えてみた。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sampleController As New SampleController()
MsgBox(sampleController.GetCount(Me.PrintPreviewControl1.Document))
End Sub
Public Class SampleController
Inherits System.Drawing.Printing.PreviewPrintController
Private Pages As Integer
Public Overrides Sub OnStartPrint(ByVal document As System.Drawing.Printing.PrintDocument, ByVal e As System.Drawing.Printing.PrintEventArgs)
MyBase.OnStartPrint(document, e)
Pages = 0
End Sub
Public Overrides Sub OnEndPage(ByVal document As System.Drawing.Printing.PrintDocument, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
MyBase.OnEndPage(document, e)
Pages += 1
End Sub
Public Function GetCount(ByVal doc As PrintDocument) As Integer
Dim cntlbak = doc.PrintController
doc.PrintController = Me
doc.Print()
doc.PrintController = cntlbak
Return Pages
End Function
End Class
|