473,382 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 22092
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
3
by: John Peterson | last post by:
Hello all! I'm at my wits end trying to search for what I assumed to be a relatively straightforward task. I have a Web application written in C#, and I have a button on the form that I want to...
1
by: Dreamtime | last post by:
Hi I am using Visual Studio 2005 and the bundled Crystal Reports (previously I used .net 2003 and bundled Crystal Reports for 2 years - same issues!) I have a report which is displayed in the...
6
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
6
by: randy1200 | last post by:
I'm using Visual Studio 2005 and C#. I need to print a WinForm used for data entry as a graphic. In other words, I need to print the exact WinForm the user sees on the screen. I searched through...
2
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
2
by: deepakfordotnet | last post by:
Hi, First of all let me confess that I could not get the solution to the same problem from an earlier post Printing :by Mr.Richard MSL (dated September 24th 2006) working. (Replied by Mr.Walter...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.