Skip to main content
.NET Framework Class Library
PrintDialog Class

Invokes a standard Microsoft Windows print dialog box that configures a PrintTicket and PrintQueue according to user input and then prints a document.

Inheritance Hierarchy
SystemObject
  System.Windows.ControlsPrintDialog

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax
Public Class PrintDialog
public class PrintDialog
public ref class PrintDialog
type PrintDialog =  class end
<PrintDialog .../>

The PrintDialog type exposes the following members.

Constructors
  NameDescription
Public method PrintDialogInitializes a new instance of the PrintDialog class.
Top
Properties
  NameDescription
Public property CurrentPageEnabledGets or sets a value that indicates whether the option to print the current page is enabled.
Public property MaxPageGets or sets the highest page number that is allowed in page ranges.
Public property MinPageGets or sets the lowest page number that is allowed in page ranges.
Public property PageRangeGets or sets the range of pages to print when PageRangeSelection is set to UserPages.
Public property PageRangeSelectionGets or sets the PageRangeSelection for this instance of PrintDialog.
Public property PrintableAreaHeightGets the height of the printable area of the page.
Public property PrintableAreaWidthGets the width of the printable area of the page.
Public property PrintQueueGets or sets a PrintQueue that represents the printer that is selected.
Public property PrintTicketGets or sets the PrintTicket that is used by the PrintDialog when the user clicks Print for the current print job.
Public property SelectedPagesEnabledGets or sets a value that indicates whether the option to print the selected pages is enabled.
Public property UserPageRangeEnabledGets or sets a value that indicates whether users of the Print dialog box have the option to specify ranges of pages to print.
Top
Methods
  NameDescription
Public method Equals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCodeServes as the default hash function. (Inherited from Object.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public method PrintDocumentPrints a DocumentPaginator object to the PrintQueue that is currently selected.
Public method PrintVisualPrints a visual (non-text) object, which is derived from the Visual class, to the PrintQueue that is currently selected.
Public method ShowDialogInvokes the PrintDialog as a modal dialog box.
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Remarks

A user can use the Print dialog box to select a printer, configure it, and perform a print job.

Strictly speaking, you can use the PrintDocument 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 AddJob method or one of the many Write and WriteAsync methods of the XpsDocumentWriter. For more about this, see How to: Programmatically Print XPS Files.

Do not confuse this class, System.Windows.ControlsPrintDialog, with System.Windows.FormsPrintDialog. The latter is used with Windows Forms applications. System.Windows.ControlsPrintDialog is used with Windows Presentation Foundation (WPF) applications. 

Examples

The following example shows how to create an instance of and display a simple PrintDialog by using Extensible Application Markup Language (XAML) markup and code.

<Button Width="200" Click="InvokePrint">Invoke PrintDialog</Button>

...

		Private Sub InvokePrint(ByVal sender As Object, ByVal e As RoutedEventArgs)
				' Create the print dialog object and set options
				Dim pDialog As New PrintDialog()
				pDialog.PageRangeSelection = PageRangeSelection.AllPages
				pDialog.UserPageRangeEnabled = True

				' Display the dialog. This returns true if the user presses the Print button.
				Dim print? As Boolean = pDialog.ShowDialog()
				If print = True Then
					Dim xpsDocument As New XpsDocument("C:\FixedDocumentSequence.xps", FileAccess.ReadWrite)
					Dim fixedDocSeq As FixedDocumentSequence = xpsDocument.GetFixedDocumentSequence()
					pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job")
				End If
		End Sub
private void InvokePrint(object sender, RoutedEventArgs e)
    {
        // Create the print dialog object and set options
        PrintDialog pDialog = new PrintDialog();
        pDialog.PageRangeSelection = PageRangeSelection.AllPages;
        pDialog.UserPageRangeEnabled = true;

        // Display the dialog. This returns true if the user presses the Print button.
        Nullable<Boolean> print = pDialog.ShowDialog();
        if (print == true)
        {
            XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
            FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
            pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
        }
    }
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.