Method
PrinterSetup.ShowPrinterDialog
Description
Displays the standard Print dialog box and returns a Graphics object in order to print to the currently selected printer.
Notes
The ShowPrinterDialog function returns a Graphics object. The various drawing routines can then be used to draw into the Graphics object and will be sent to the printer for printing. You can get the values in the Copies, From and To fields of the Print dialog box using the Copies, FirstPage and LastPage properties of the Graphics object returned by the ShowPrinterDialog function.
If the user clicks the Cancel button, the ShowPrinterDialog function returns Nil.
Although the pageSetup parameter is optional, in order to get the correct horizontal and vertical resolutions for drawing and positioning you will need to provide a PrinterSetup. You can do this without prompting the user with a dialog like this:
Var g As Graphics
Var ps As New PrinterSetup
g = ps.ShowPrinterDialog(MyWindow)
Var horizontalDPI = ps.HorizontalResolution
Var verticalDPI = ps.VerticalResolution
Sample code
This example prints "Hello World" to the currently selected printer.
Var ps As New PrinterSetup
Var g As Graphics
g = ps.ShowPrinterDialog
If g <> Nil Then
' Draw text 1 inch across and 1 inch down
g.DrawText("Hello World", ps.HorizontalResolution, ps.VerticalResolution)
End If
This example uses the Page Setup properties for the printer chosen by the user by the PageSetup dialog:
Var ps As New PrinterSetup
If ps.ShowPageSetupDialog Then
Var g As Graphics
g = ps.ShowPrinterDialog
If g <> Nil Then
' Draw text 1 inch across and 1 inch down
g.DrawText("Hello World", ps.HorizontalResolution, ps.VerticalResolution)
End If
End If
This example checks if the Windows printer supports alpha blending:
Declare Function GetDeviceCaps Lib "gdi32" ( hdc As Ptr, index As Int32 ) As Int32
Const SHADEBLENDCAPS = 120
Const SB_NONE = 0
Const SB_CONST_ALPHA = 1
Const SB_PIXEL_ALPHA = 2
Const SB_PREMULT_ALPHA = 4
Const SB_GRAD_RECT = &h10
Const SB_GRAD_TRI = &h20
Var ps As New PrinterSetup
Var g As Graphics = ps.ShowPrinterDialog
Var hdc As Ptr = g.Handle(Graphics.HandleTypes.HDC)
If GetDeviceCaps(hdc, SHADEBLENDCAPS) = SB_NONE Then
MessageBox("This Printer does not support alpha blending.")
Else
MessageBox("Yay! This Printer supports alpha blending.")
End If
Compatibility
All project types on all supported operating systems.
See also
PrinterSetup parent class; Graphics, PrinterSetup, StyledTextPrinter classes; PrinterSetup.OpenPrinter function.