Question

I have such a problem here. I have a window in my WPF project, and have a button, with what I want To print With printer that page. My click event for that button is this.

PrintDialog dlg = new PrintDialog();
Window currentMainWindow = Application.Current.MainWindow;
Application.Current.MainWindow = this;
if ((bool)dlg.ShowDialog().GetValueOrDefault())
{
     Application.Current.MainWindow = currentMainWindow; 
}

When I click on buton, the Print dialog is popped out. Here enter image description here But When clicking on print, nothing happenes, the dialog is just closing, and no results, it is not working not with Adobe PDF, not with ARX CoSign...

What to do ? Thanks

Was it helpful?

Solution

The rough working

    var printDoc = new PrintDocument()
    var dlg = new PrintDialog()

    If(dlg.ShowDialog() == DialogResult.OK)
    {
           printDoc.Document = [doc to print]
           printDoc.Setting = dlg.settings
           PrintDoc.print()
    }

OTHER TIPS

enter code here

PrintDialog dlg = new PrintDialog();
Window currentMainWindow = Application.Current.MainWindow;

        Application.Current.MainWindow = this;

        if ((bool)dlg.ShowDialog().GetValueOrDefault())
        {
            Application.Current.MainWindow = currentMainWindow; // do it early enough if the 'if' is entered
            dlg.PrintVisual(this, "Certificate");
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top