Export (0) Print
Expand All

PrintDialog.ShowDialog Method

Invokes the PrintDialog as a modal dialog box.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)

public Nullable<bool> ShowDialog ()
public Nullable<boolean> ShowDialog ()
public function ShowDialog () : Nullable<boolean>
You cannot use methods in XAML.

Return Value

true if a user clicks Print; false if a user clicks Cancel; or a null reference (Nothing in Visual Basic) if a user closes the dialog box without clicking Print or Cancel.

The following example shows how to use the ShowDialog method in code.

public 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");
        }
    }

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft