Microsoft Docs Search

PrintDialog Class

The PrintDialog class provides a standard dialog that enables users to select a printer, set the number of copies, choose page ranges, and configure other printing options.

Namespace

Windows.UI.Dialogs

Assembly

Windows.UI.dll

Syntax

public sealed class PrintDialog : IPrintDialog
{
    public PrintDialog();
    public bool Show();
    public string PrinterName { get; set; }
    public int Copies { get; set; }
    public bool Collate { get; set; }
    public bool PrintToFile { get; set; }
    public PrintPageRange PageRange { get; set; }
    // Additional members...
}

Members

MemberTypeDescription
Show()boolDisplays the dialog and returns true if the user confirms.
PrinterNamestringThe name of the selected printer.
CopiesintNumber of copies to print.
CollateboolWhether to collate multiple copies.
PrintToFileboolEnable printing to a file (e.g., PDF).
PageRangePrintPageRangeSpecifies which pages to print.

Remarks

The PrintDialog automatically adapts to the printer capabilities reported by the system. When PrintToFile is true, the dialog prompts the user to specify an output file path.

Example

using Windows.UI.Dialogs;

void ShowPrintDialog()
{
    var dlg = new PrintDialog
    {
        Copies = 1,
        Collate = true,
        PrintToFile = false,
        PageRange = new PrintPageRange { From = 1, To = 5 }
    };

    if (dlg.Show())
    {
        // Retrieve the selected printer
        string printer = dlg.PrinterName;
        // Initiate printing with the chosen settings
        PrintDocument(printer, dlg);
    }
}

See Also