Frage

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

War es hilfreich?

Lösung

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()
    }

Andere Tipps

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");
        }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top