Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-invoke-a-print-dialog.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

2.7 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Invoke a Print Dialog 03/30/2017
csharp
vb
invoking print dialogs [WPF]
print dialogs [WPF], invoking
e3a2c84c-74fe-45a4-8501-5813f9dbfed2

How to: Invoke a Print Dialog

To provide the ability to print from you application, you can simply create and open a xref:System.Windows.Controls.PrintDialog object.

Example

The xref:System.Windows.Controls.PrintDialog control provides a single entry point for [!INCLUDETLA2#tla_ui], configuration, and XPS job submission. The control is easy to use and can be instantiated by using [!INCLUDETLA#tla_xaml] markup or code. The following example demonstrates how to instantiate and open the control in code and how to print from it. It also shows how to ensure that the dialog will give the user the option of setting a specific range of pages. The example code assumes that there is a file FixedDocumentSequence.xps in the root of the C: drive.

[!code-csharpprintdialog#1] [!code-vbprintdialog#1]

Once the dialog is open, users will be able to select from the printers installed on their computer. They will also have the option of selecting the Microsoft XPS Document Writer to create an XML Paper Specification (XPS) file instead of printing.

Note

The xref:System.Windows.Controls.PrintDialog?displayProperty=nameWithType control of WPF, which is discussed in this topic, should not be confused with the xref:System.Windows.Forms.PrintDialog?displayProperty=nameWithType component of Windows Forms.

Strictly speaking, you can use the xref:System.Windows.Controls.PrintDialog.PrintDocument%2A method without ever opening the dialog. In that sense, the control can be used as an unseen printing component. But for performance reasons, it would be better to use either the xref:System.Printing.PrintQueue.AddJob%2A method or one of the many xref:System.Windows.Xps.XpsDocumentWriter.Write%2A and xref:System.Windows.Xps.XpsDocumentWriter.WriteAsync%2A methods of the xref:System.Windows.Xps.XpsDocumentWriter. For more about this, see Programmatically Print XPS Files.

See also