|
Subject:
|
Printing a VB Text Box Directly To a Printer
|
|
Posted By:
|
CB78
|
Post Date:
|
2/13/2004 12:05:19 PM
|
Hi All,
I hope this is a simple question someone can answer for me, so here goes. I am currently working on a GUI in VB6 for a 911 center in which I need to be able to have the print button print directly to a printer over a serial connection without bringing up a print dialog box because the operators can't have any windows popping up in front of the caller info. The only thing that needs to be sent to the printer is the data contained within a normal text box. Thanks for any help I can get!
-CB
|
|
Reply By:
|
Yehuda
|
Reply Date:
|
2/13/2004 12:14:16 PM
|
The Printer hasa hidden function print that works as follows:
Printer.Print textBox1.text
|
|
Reply By:
|
marcostraf
|
Reply Date:
|
2/13/2004 1:22:21 PM
|
Be careful here.
First of all, the user must have a default printer installed in her/his machine, otherwise the Printer object is nothing. The Print method prints starting at the CurrentX,CurrentY coordinates (default 0,0 maybe you want to change those). If the text box is set to word wrap, the Text property is a long string without newlines, thus can easily go outside the page border. Finally, you have to invoke the Printer.EndDoc method to print the page after you are done with all the printing. To delete the print job, just call Printer.KillDoc. More info in the "Printer Object, Printers Collection" VB/MSDN help page
Marco
quote: Originally posted by Yehuda
The Printer hasa hidden function print that works as follows:
Printer.Print textBox1.text
|
|
Reply By:
|
Yehuda
|
Reply Date:
|
2/13/2004 1:27:46 PM
|
You can set the default Printer through the printers collection. But Marco is right, it definitely would pay to read up more on the printer and printers object before using it.
|
|
Reply By:
|
CB78
|
Reply Date:
|
2/13/2004 4:38:38 PM
|
OK, Well what if I don't necessarily want to use the default printer, but one of the other predefined printers. I'm not sure they want the Ambulance printer to be their default printer for all apps, just for this one GUI when they press the print button. I also already have the contents printed out to a txt file, so it's possible just to print the contents of that file if it makes it easier.
Thanks, CB
|
|
Reply By:
|
CB78
|
Reply Date:
|
2/16/2004 12:22:27 PM
|
Does anyone have a way to change the default printer in a vb6 method? This way I can change it, print the text, then change it back all at the same time. Thanks.
CB
|
|
Reply By:
|
CB78
|
Reply Date:
|
2/16/2004 12:54:17 PM
|
Got it!
Dim p As Printer
For Each p In Printers ' Do something here If p.DeviceName = strSavedPrinter Then ' Change current printer and/or settings Set Printer = p End If Next p
This pretty much solves my problem, thanks all!
CB
|