/// <summary> /// Occurs when the Print button is clicked /// </summary> /// <param name="item">The item that has been clicked</param> protected virtual void OnPrintClick(ToolStripButton item) { if (PdfViewer.Document.FormFill != null) { PdfViewer.Document.FormFill.ForceToKillFocus(); } //Show standard print dialog var printDoc = new PdfPrintDocument(PdfViewer.Document); var dlg = new PrintDialog(); dlg.AllowCurrentPage = true; dlg.AllowSomePages = true; dlg.UseEXDialog = true; dlg.Document = printDoc; OnPdfPrinDocumentCreaded(new EventArgs <PdfPrintDocument>(printDoc)); ShowPrintDialogDelegate showprintdialog = ShowPrintDialog; this.BeginInvoke(showprintdialog, dlg); //this.BeginInvoke(new Action(() => //{ // if (dlg.ShowDialog() == DialogResult.OK) // { // PrintController printController = new StandardPrintController(); // printDoc.PrintController = printController; // printDoc.Print(); // } //})); }
/// <summary> /// Occurs when the Print button is clicked /// </summary> /// <param name="item">The item that has been clicked</param> public virtual void OnPrintClick(ToolStripButton item) { if (PdfViewer.Document.FormFill != null) { PdfViewer.Document.FormFill.ForceToKillFocus(); } //Show standard print dialog var printDoc = new PdfPrintDocument(PdfViewer.Document); var dlg = new PrintDialog(); dlg.AllowCurrentPage = true; dlg.AllowSomePages = true; dlg.UseEXDialog = true; dlg.Document = printDoc; OnPdfPrinDocumentCreaded(new EventArgs <PdfPrintDocument>(printDoc)); ShowPrintDialogDelegate showprintdialog = ShowPrintDialog; //Initialize a new thread for print dialog Thread thread3 = new Thread(() => { if (dlg.ShowDialog() == DialogResult.OK) { try { this.Focus(); this.BringToFront(); Application.Exit(); dlg.Document.Print(); this.DestroyHandle(); } catch (Win32Exception) { //Printing was canceled } } }); thread3.SetApartmentState(ApartmentState.STA); thread3.Start(); thread3.Join(); }
/// <summary> /// Occurs when the Print button is clicked /// </summary> /// <param name="item">The item that has been clicked</param> protected virtual void OnPrintClick(Button item) { if (PdfViewer.Document.FormFill != null) { PdfViewer.Document.FormFill.ForceToKillFocus(); } //Show standard print dialog var printDoc = new PdfPrintDocument(PdfViewer.Document); var dlg = new System.Windows.Forms.PrintDialog(); dlg.AllowCurrentPage = true; dlg.AllowSomePages = true; dlg.UseEXDialog = true; dlg.Document = printDoc; OnPdfPrinDocumentCreaded(new EventArgs <PdfPrintDocument>(printDoc)); ShowPrintDialogDelegate showprintdialog = ShowPrintDialog; Dispatcher.BeginInvoke(showprintdialog, dlg); }