Click to See Complete Forum and Search --> : Common Dialog Control


comart
April 20th, 2001, 08:57 AM
I am using the ShowPrinter method of the common dialog control, which I thought would print my entire form. I get the printer dialog window, but I do not get anything sent to my printer. What is the trick for this to work?

shree
April 20th, 2001, 09:14 AM
The printer common dialog is for selecting a printer and setting various options. You will have to write your own code for doing the actual printing.

For instance, to print the entire form, use

Me.PrintForm

This will print to the printer that the user selected via your printer common dialog (or to the default printer on your system even if you don't show the printer dialog box).

To print text, you would use the Print method, whereas to print other graphics, you would use Printer.PaintPicture.

comart
April 20th, 2001, 09:16 AM
Is there a way to print the contents of a listbox that scrolls vertically?

shree
April 20th, 2001, 09:19 AM
for i = 0 to List1.ListCount-1
print List1.List(i)
next

comart
April 20th, 2001, 09:34 AM
This code prints to the form--not the printer. Is there a way to print the listbox contents to the printer?

shree
April 20th, 2001, 09:37 AM
Sorry, use

Printer.Print

comart
April 20th, 2001, 09:58 AM
There is no print method for the printer object. It only has a printquality property. Am I missing something here?

shree
April 20th, 2001, 10:07 AM
Though IntelliSense doesn't show it (is that a bug?), there's still a Print method for the Picturebox control and the Printer Object. So, go on with it. Only remember to put a Printer.EndDoc at the end of the loop, otherwise your application will start to print after you close your application!

comart
April 20th, 2001, 10:17 AM
Dim myPrinter As Printer
Dim n As Integer
Set myPrinter = Printer
For n = 0 To List1.ListCount - 1
myPrinter.Print List1.List(n)
Next
Printer.EndDoc

When I run this code, it bombs at the line myprinter.print

shree
April 20th, 2001, 10:23 AM
It works fine on my system. Do you have a printer installed on your system?

comart
April 20th, 2001, 10:26 AM
Yes, I do. I'm wondering if our network is set up in a way that prevents this from working.

Ughh!

comart
April 20th, 2001, 11:24 AM
Just thought you'd like to know. I took out this line of code printer = commondialog1.PrinterDefault

Now it works. I cannot understand why that hoses my printer, but I'm just happy that I can print now.

Thanks for all your help.

shree
April 20th, 2001, 11:35 AM
Good.

You put the PrinterDefault property to wrong use. This property returns or sets an option that determines if the user's selections in the Print dialog box are used to change the system's default printer settings.

If you included this line to tell Visual Basic to use the default printer, you do not have to. Visual Basic always uses the default printer to print unless the user chooses to print to a different printer via the print dialog box.