<div class="meta" robots="noindex">

</div>

Method

# OpenPrinterDialog

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `ShowPrinterDialog<printersetup.showprinterdialog>` as a replacement.

</div>

## Description

Displays the standard Print dialog box and returns a `Graphics</api/graphics/graphics>` object in order to print to the currently selected printer.

## Usage

*result*=**OpenPrinterDialog**(\[*pageSetup*\]\[,*window*\])

| Part      | Type                                       | Description                                                                                                                                                                                                                                                                             |
|-----------|--------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| result    | `Graphics</api/graphics/graphics>`         | A `Graphics</api/graphics/graphics>` object that represents the page to be printed.                                                                                                                                                                                                     |
| pageSetup | `PrinterSetup</api/printing/printersetup>` | Optional. A `PrinterSetup</api/printing/printersetup>` object whose properties will be used (like page orientation, scale, etc.) when printing. Although this is optional, you will mostly likely always want to provide a PrinterSetup so that you have access to drawing resolutions. |
| window    | `Window</api/deprecated/window>`           | Optional. If you want to present the Print dialog as a Sheet window (macOS only), *window* is the window to which you want to attach the Print dialog box.                                                                                                                              |

## Notes

The <span class="title-ref">OpenPrinterDialog</span> function returns a `Graphics</api/graphics/graphics>` object. The various drawing routines can then be used to draw into the `Graphics</api/graphics/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</api/graphics/graphics>` object returned by the <span class="title-ref">OpenPrinterDialog</span> function.

If the user clicks the Cancel button, the <span class="title-ref">OpenPrinterDialog</span> function returns `Nil</api/language/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:

``` xojo
Dim p As New PageSetup
g = OpenPrinterDialog(p, MyWindow)
Dim horizontalDPI = p.HorizontalResolution
Dim verticalDPI = p.VerticalResolution
```

## Sample code

This example prints "Hello World" to the currently selected printer.

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This example uses the Page Setup properties for the printer chosen by the user by the PageSetup dialog:

``` xojo
Dim ps As New PrinterSetup
If ps.PageSetupDialog Then
  Dim g As Graphics
  g = OpenPrinterDialog(ps)
  If g <> Nil Then
    ' Draw text 1 inch across and 1 inch down
    g.DrawString("Hello World", ps.HorizontalResolution, ps.VerticalResolution)
  End If
End If
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This example checks if the Windows printer supports alpha blending:

``` xojo
Declare Function GetDeviceCaps Lib "gdi32" ( hdc As Integer, 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

Dim g As Graphics = OpenPrinterDialog(Nil, Nil)
Dim hdc As Integer = g.Handle(Graphics.HandleTypeHDC)

If GetDeviceCaps(hdc, SHADEBLENDCAPS) = SB_NONE Then
  MsgBox("This Printer does not support alpha blending")
Else
  MsgBox("Yay! This Printer supports alpha blending")
End If
```

## Compatibility

All project types on all supported operating systems.

## See also

`Graphics</api/graphics/graphics>`, `PrinterSetup</api/printing/printersetup>`, `StyledTextPrinter</api/printing/styledtextprinter>` classes; `PrinterSetup.OpenPrinter<printersetup.openprinter>` function.
