PrintDialog Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Invokes a standard Microsoft Windows print dialog box that configures a PrintTicket and PrintQueue according to user input and then prints a document.
public ref class PrintDialog
public class PrintDialog
type PrintDialog = class
Public Class PrintDialog
- Inheritance
-
PrintDialog
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 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.Value)
{
XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
}
}
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
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.Controls.PrintDialog, with System.Windows.Forms.PrintDialog. The latter is used with Windows Forms applications. System.Windows.Controls.PrintDialog is used with Windows Presentation Foundation applications.
Constructors
PrintDialog() |
Initializes a new instance of the PrintDialog class. |
Properties
CurrentPageEnabled |
Gets or sets a value that indicates whether the option to print the current page is enabled. |
MaxPage |
Gets or sets the highest page number that is allowed in page ranges. |
MinPage |
Gets or sets the lowest page number that is allowed in page ranges. |
PageRange |
Gets or sets the range of pages to print when PageRangeSelection is set to UserPages. |
PageRangeSelection |
Gets or sets the PageRangeSelection for this instance of PrintDialog. |
PrintableAreaHeight |
Gets the height of the printable area of the page. |
PrintableAreaWidth |
Gets the width of the printable area of the page. |
PrintQueue |
Gets or sets a PrintQueue that represents the printer that is selected. |
PrintTicket |
Gets or sets the PrintTicket that is used by the PrintDialog when the user clicks Print for the current print job. |
SelectedPagesEnabled |
Gets or sets a value that indicates whether the option to print the selected pages is enabled. |
UserPageRangeEnabled |
Gets or sets a value that indicates whether users of the Print dialog box have the option to specify ranges of pages to print. |
Methods
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
PrintDocument(DocumentPaginator, String) |
Prints a DocumentPaginator object to the PrintQueue that is currently selected. |
PrintVisual(Visual, String) |
Prints a visual (non-text) object, which is derived from the Visual class, to the PrintQueue that is currently selected. |
ShowDialog() |
Invokes the PrintDialog as a modal dialog box. |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |
Applies to
.NET