Click to See Complete Forum and Search --> : Printing and print preview Image problems


niro
February 3rd, 2009, 10:42 AM
I'm having problem with the print preview of image in a picturebox. The print preview dialog appears but with a plain white page only. Does anyone know what the problem is?

Also how would i incorporate the page settings feature when i click on "print". So that instead of just printing the image straight away it would show the page settings dialog so I could choose the printer to print from or change the page settings.

The code i'm using is below:


Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Try
AddHandler PrintDocument1.PrintPage, AddressOf OnPrintPage
PrintDocument1.Print()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub OnPrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
e.Graphics.DrawImage(PictureBox1.Image, 0, 0)
End Sub

Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click
Try
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Any help would be much appreciated!
THANKS! =)

jmedved
February 4th, 2009, 09:14 AM
Hi,

You need to add handler to PrintPage event for print preview also. Maybe the best thing would be to move it to New or Form_Load.
As for print settings, check PrintDialog control.

niro
February 7th, 2009, 08:45 AM
thanks for your reply
could you further explain "add handler to PrintPage event for print preview also" please?

dglienna
February 7th, 2009, 12:37 PM
Your search button broken? http://www.startvbdotnet.com/controls/printdialog.aspx