Automatic printing to default printer?


I’m running Xojo 2018 R1 on Windows 10. Is it possible to automatically print to the default printer versus the user having to select a printer via the OpenPrinterDialog each time? I’d like for them to simply press a Print button and not have to worry about choosing a printer.

Thank you.

Look at WindowsPrinterMBS Get/Set DefaultPrinter methods. This is what we use to select a printer via code.

Thank you, Bob! That does the trick!

Just call:

g = OpenPrinter(p)

instead of

g = OpenPrinterDialog(p)

and it will give you a graphics object to the default printer.


Dim p As New PrinterSetup Dim g As Graphics g = OpenPrinter(p) If g <> Nil Then // Draw text 1 inch across and 1 inch down g.DrawString("Hello World", p.HorizontalResolution, p.VerticalResolution) End If

Right, but if, for example, you have a barcode printer and a regular report printer, there’s no easy way to handle both without going into a print dialog. Using the WindowPrinterMBS class you can select which one is your barcode printer and which one is your regular report printer.

Yup yup :slight_smile: I just double checked what Rafael asked and made sure he got the answer he was after :slight_smile:

nice spam parker