469,313 Members | 2,570 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,313 developers. It's quick & easy.

Printing using the print dialog control in vb.net 2005

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

Mar 12 '07 #1
2 21767
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.

Mar 13 '07 #2
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.

Mar 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Jody Gelowitz | last post: by
3 posts views Thread by John Peterson | last post: by
1 post views Thread by Dreamtime | last post: by
6 posts views Thread by randy1200 | last post: by
2 posts views Thread by Brad Pears | last post: by
18 posts views Thread by Brett | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.