Home All Groups Group Topic Archive Search About
Author
4 Dec 2006 12:30 PM
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?

Author
4 Dec 2006 5:14 PM
RobinS
You could try setting it to nothing:

  MyPrintPreview.Document = Nothing

Robin S.
----------------------------------------
Show quoteHide quote
"Stuart Nathan" <stuart.nat***@homecall.co.uk> wrote in message
news:uclQbA6FHHA.1248@TK2MSFTNGP03.phx.gbl...
> Can someone tell me how to remove a previously loaded PrintDocument in a
> PrintPreview control, so that I can display a nedw one?
>
Author
4 Dec 2006 6:14 PM
Stuart Nathan
I have.

The Code is

Preview.Document = Nothing
PrintDoc = New Drawing.Printing.PrintDocument
Preview.Document = PrintDoc
Preview.Show
Author
4 Dec 2006 6:20 PM
RobinS
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.
------------------------------------------

Show quoteHide quote
"Stuart Nathan" <stuart.nat***@homecall.co.uk> wrote in message
news:%23bZtDA9FHHA.1804@TK2MSFTNGP02.phx.gbl...
>I have.
>
> The Code is
>
> Preview.Document = Nothing
> PrintDoc = New Drawing.Printing.PrintDocument
> Preview.Document = PrintDoc
> Preview.Show
>
>
>
Author
5 Dec 2006 10:48 AM
Stuart Nathan
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
Author
5 Dec 2006 5:58 PM
RobinS
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.
------------------------------------------
Show quoteHide quote
"Stuart Nathan" <stuart.nat***@homecall.co.uk> wrote in message
news:%23ahcqrFGHHA.536@TK2MSFTNGP02.phx.gbl...
> 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
>
>
>
Author
6 Dec 2006 1:47 PM
Stuart Nathan
The answer is the .InvalidatePreview method