views:

165

answers:

1
Using printPreview As New PrintPreviewDialog()
        ' Dim x As New Printing.PrintDocument()
        ' AddHandler x.PrintPage, AddressOf PrintData
        printPreview.Document = Me.CurrentDocument
        If ShowPrinterSetup Then
            Dim x As New PrintDialog()
            x.Document = CurrentDocument
            x.ShowDialog(Anchor)
        End If
        whichPage = 0
        Return printPreview.ShowDialog(Anchor)
End Using

So far no matter what I clicked in printpreview, the showdialog returns cancel? How can I tell if the user did print? I'd like to clear the print queue of items if they did actually print to a printer or ask them if I should clear it, but only if they actually did print something.

A: 

You can get the result of the print job from the CurrentDocument EndPrint event

Private WithEvents CurrentDocument As New PrintDocument

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Using printPreview As New PrintPreviewDialog()
        printPreview.Document = Me.CurrentDocument
        printPreview.ShowDialog()
    End Using
End Sub

Private Sub document_EndPrint(ByVal sender As Object, ByVal e As PrintEventArgs) Handles CurrentDocument.EndPrint
    If e.PrintAction = PrintAction.PrintToPrinter Then
        MsgBox("Document Printed to Printer")
    End If
End Sub
Bob