Printing using the print dialog control in vb.net 2005

B

Brad Pears

I have some sample code that uses the print dialog, print preview and a
print direct options.

If I select print preview and then click the printer icon from that, the
document prints. If I select the print directly option, it also prints right
away to the defauilt printer.

However, if I use the printer dialog control to print and I click 'OK' to
actually print the document - nothing happens. The job does not even go into
the print queue (I checked as I printed) No error messages are generated -
just nothing happens.

Any ideas?? PS (the page setup dialog control also does not print)

Here is the code...

Imports System.Drawing.Printing

Public Class Form1

Inherits System.Windows.Forms.Form

' Display a print preview.

Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrintPreview.Click

' Make a PrintDocument and attach it to

' the PrintPreview dialog.

dlgPrintPreview.Document = PreparePrintDocument()

' Preview.

dlgPrintPreview.WindowState = FormWindowState.Maximized

dlgPrintPreview.ShowDialog()

End Sub

' Print with the print dialog.

Private Sub btnPrintWithDialog_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnPrintWithDialog.Click

' Make a PrintDocument and attach it to

' the Print dialog.

dlgPrint.Document = PreparePrintDocument()

' Display the print dialog.

dlgPrint.ShowDialog()

End Sub

' Print immediately.

Private Sub btnPrintNow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrintNow.Click

' Make a PrintDocument object.

Dim print_document As PrintDocument = PreparePrintDocument()

' Print immediately.

print_document.Print()

End Sub

' Make and return a PrintDocument object that's ready

' to print the paragraphs.

Private Function PreparePrintDocument() As PrintDocument

' Make the PrintDocument object.

Dim print_document As New PrintDocument

' Install the PrintPage event handler.

AddHandler print_document.PrintPage, AddressOf Print_PrintPage

' Return the object.

Return print_document

End Function

' Print the next page.

Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs)

Dim imagePrint As Image = Image.FromFile("c:\gord.bmp")

e.Graphics.DrawImage(imagePrint, 50, 50, imagePrint.Width,
imagePrint.Height)

' No more pages

e.HasMorePages = False

End Sub

End Class
 
C

ClayB

Try calling the Print method on your Document after the dialog comes
back with an OK.

If dlgPrint.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
dlgPrint.Document.Print()
End If

======================
Clay Burch
Syncfusion, Inc.
 
C

ClayB

Try calling the Print method on your Document after the dialog comes
back with an OK.

If dlgPrint.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
dlgPrint.Document.Print()
End If

======================
Clay Burch
Syncfusion, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top