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
| Member | Type | Description |
|---|---|---|
Show() | bool | Displays the dialog and returns true if the user confirms. |
PrinterName | string | The name of the selected printer. |
Copies | int | Number of copies to print. |
Collate | bool | Whether to collate multiple copies. |
PrintToFile | bool | Enable printing to a file (e.g., PDF). |
PageRange | PrintPageRange | Specifies 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);
}
}