Search code examples
c#wpfprintdialog

Can not Print in WPF


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


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