By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

Printing using the print dialog control in vb.net 2005

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.