PrintPreview Control

  • Thread starter Thread starter Stuart Nathan
  • Start date Start date
S

Stuart Nathan

Can someone tell me how to remove a previously loaded PrintDocument in a
PrintPreview control, so that I can display a nedw one?
 
I have.

The Code is

Preview.Document = Nothing
PrintDoc = New Drawing.Printing.PrintDocument
Preview.Document = PrintDoc
Preview.Show
 
Okay, I'm no print expert, but I'll give this
a try.

This is how I'm doing it:

Preview.Document = ProductPrintDocument
Preview.ShowDialog()

Where ProductPrintDocument is my PrintDocument.
Then I have an event handler for
ProductPrintDocument.PrintPage that actually
outputs the information.

Is that how you're doing it?

Robin S.
 
No.

I created it using
Dim WithEvents Preview as PrintPreviewControl

I have tried a standard Dim statement and then adding an AddHandlern but no
difference there.

I do the "printing" in the PrintPage event, but this event is not raised
again even if I change the PrintPreview.Document
 
I'm on event expert, but here's what I think.
If you dim something WithEvents, you can raise
events and capture events on it. Are you doing
that?

The PrintPreviewControl already has events, and
you should be able to capture them inherently.
On your form, click on the PrintPreviewControl
and look at the properties. If you click on the
lightning bolt, it will show you the addressable
events. Although, I don't know why you would
need to do this.

Here is the code I'm using for my PrintPreview
and Print buttons. My PrintPage event is below also.
Will this work for you?

Private Sub PrintButton(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles PrintToolStripButton.Click,
PrintToolStripMenuItem.Click
'This calls PrintPage for each page in ProductPrintDocument
'so that means it ends up calling ProductPrintDocument_PrintPage
' because that handles the ProductPrintDocument.PrintPage event.
' page in ProductPrintDocument.
ProductPrintDocument.Print()
End Sub

Private Sub PrintPreviewButton(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles PrintPreviewToolStripButton.Click, _
PrintPreviewToolStripMenuItem.Click
ProductPrintPreview.Document = ProductPrintDocument
'this shows the document in PrintPreview mode
'the user can print it from there or cancel
ProductPrintPreview.ShowDialog()
End Sub

Private Sub ProductPrintDocument_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles ProductPrintDocument.PrintPage
Try
ProcessPrintPage(sender, e)
Catch ex As InvalidOperationException
MessageBox.Show(My.Resources.PrintErrActiveForm)
End Try
End Sub

Robin S.
 
Back
Top