/// <summary> /// 打印预览 /// </summary> /// <param name="bmp"></param> /// <param name="isCut"></param> /// <param name="tp"></param> public void PrintView(Bitmap bmp, bool isCut, bool tp) { if (bmp == null) { return; } ImageCut = isCut; IsTp = tp; PrintBitmap = new Bitmap(bmp.Width, bmp.Height); var g = Graphics.FromImage(PrintBitmap); g.DrawImage(bmp, 0, 0, PrintBitmap.Width, PrintBitmap.Height); g.Dispose(); var pv = new PrintPreviewDialog { Document = DocumentPrint }; pv.ShowDialog(); pv.Dispose(); GC.Collect(); }
// Do a print preview of the descriptions. public void PrintPreview(Size dialogSize) { // Set up and position everything. SetupPrinting(); printPreviewInProgress = true; using (PrintDocument printDocument = CreatePrintDocument()) { PrintPreviewDialog dialog = new PrintPreviewDialog(); dialog.UseAntiAlias = true; dialog.Document = printDocument; dialog.StartPosition = FormStartPosition.CenterParent; dialog.Size = dialogSize; dialog.SizeGripStyle = SizeGripStyle.Show; dialog.ShowIcon = false; // Remove the "print" button. foreach (Control ctl in dialog.Controls) { ToolStrip strip = ctl as ToolStrip; if (strip != null) { var button = strip.Items[0]; if (button.Name == "printToolStripButton") { strip.Items.Remove(button); } } } dialog.ShowDialog(); dialog.Dispose(); } }
public PrintReport(string imageFileName) { _doc = new PrintDocument(); _imageFileName = imageFileName; try { _doc.PrintPage += new PrintPageEventHandler(_doc_PrintPage); _doc.PrinterSettings.DefaultPageSettings.Landscape = true; _doc.PrinterSettings.DefaultPageSettings.Margins = new Margins(50, 50, 50, 50); var dialog = new PrintDialog(); dialog.Document = _doc; if (dialog.ShowDialog() == DialogResult.OK) { PrintPreviewDialog prev = new PrintPreviewDialog(); prev.Document = _doc; prev.ShowDialog(); prev.Dispose(); //_doc.Print(); } dialog.Dispose(); _doc.Dispose(); } catch (Exception error) { MessageBox.Show("Error imprimiendo.", "UTN Emall", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void B_PrintPreviewDialog_Click(object sender, EventArgs e) { PrintPreviewDialog dlg = new PrintPreviewDialog(); dlg.ShowDialog(); dlg.Dispose(); }
private void toolStripButtonPreview_Click(object sender, EventArgs e) { pagesIndex = 0; isPDFPrint = false; isShowPrintDialog = false; MyPrintPreviewDg = new PrintPreviewDialog(); MyPrintPreviewDg.ShowIcon = false; MyPrintPreviewDg.UseAntiAlias = true; try { printDocument.DefaultPageSettings.PaperSize.RawKind = (int)PaperKind.A4; } catch { } // will throw exception when no default printer is set printDocument.DefaultPageSettings.Landscape = report.Landscape; MyPrintPreviewDg.Document = printDocument; try { MyPrintPreviewDg.ShowDialog(); MyPrintPreviewDg.Dispose(); } catch { printDocument.PrintController.OnEndPrint(printDocument, new System.Drawing.Printing.PrintEventArgs()); } }
protected virtual void Dispose(bool disposing) { if (disposing) { printDocument.Dispose(); printDialog.Dispose(); printPreviewDialog.Dispose(); } }
/// <summary> /// Cleans up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected void Dispose(bool disposing) { if (disposing) { printDocument1.Dispose(); printPreviewDialog1.Dispose(); _frm.Dispose(); imagen.Dispose(); } }
private void RuntimeDialog() { PrintPreviewDialog pPDlg; pPDlg = new PrintPreviewDialog(); pPDlg.Document = printDocument1; pPDlg.WindowState = FormWindowState.Maximized; pPDlg.PrintPreviewControl.Columns = 2; pPDlg.ShowDialog(); pPDlg.Dispose(); }
/// <summary> /// 打印预览 /// </summary> /// <param name="printfile">打印文件路径</param> public void PrintView(string printfile) { PrintBitmap = ImageHepler.LoadBitmap(printfile); var pv = new PrintPreviewDialog { Document = DocumentPrint }; pv.ShowDialog(); pv.Dispose(); GC.Collect(); }
private void VistaPreliminar() { PrintPreviewDialog VPDialogo = default(PrintPreviewDialog); VPDialogo = new PrintPreviewDialog(); VPDialogo.WindowState = FormWindowState.Maximized; VPDialogo.Document = this.printDocument1; VPDialogo.PrintPreviewControl.StartPage = 0; VPDialogo.ShowDialog(); VPDialogo.Dispose(); }
public void PrintView(List <IPrintPaperData> printData) { PrintPaperData = printData; var pv = new PrintPreviewDialog { Document = DocumentPrint }; pv.ShowDialog(); pv.Dispose(); GC.Collect(); }
protected virtual void Dispose(bool disposing) { try { if (disposing) { printDocument.Dispose(); printDialog.Dispose(); printPreviewDialog.Dispose(); } } catch (Exception) { } }
private void button2_Click(object sender, System.EventArgs e) { pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); pd.PrinterSettings.PrinterName = "PDFCreator"; pd.DocumentName = "PDFCreator Dot Net - Sample2"; PrintPreviewDialog ppdlg = new PrintPreviewDialog(); ppdlg.Document = pd; ppdlg.WindowState = FormWindowState.Maximized; ppdlg.ShowDialog(); ppdlg.Dispose(); }
public void PrintPreview() { PrintDocument printDoc = new PrintDocument(); printDoc.PrintPage += EnvironmentPrint; PrintPreviewDialog dlg = new PrintPreviewDialog { Document = printDoc }; dlg.ShowDialog(); dlg.Dispose(); printDoc.Dispose(); }
public void Dispose() { if (printDocument != null) { printDocument.Dispose(); } if (printDialog != null) { printDialog.Dispose(); } if (printPreviewDialog != null) { printPreviewDialog.Dispose(); } }
public void PrinterSetting() { PrintDialog pDlg = new PrintDialog(); PrintPreviewDialog ppDlg = new PrintPreviewDialog(); try { //声明返回值的PrinterSettings PrinterSettings ps = new PrinterSettings(); //可以选定页 pDlg.AllowSomePages = true; //指定打印文档 pDlg.Document = document; //显示对话框 DialogResult result = pDlg.ShowDialog(); if (result == DialogResult.OK) { //保存打印设置 ps = pDlg.PrinterSettings; ppDlg.Text = "打印预览"; ppDlg.WindowState = FormWindowState.Maximized; ppDlg.PrintPreviewControl.Zoom = 1; //指定打印文档 ppDlg.Document = document; ppDlg.ShowDialog(); } } catch (System.Drawing.Printing.InvalidPrinterException e) { MessageBox.Show("请先在控制面板添加打印机!", "未找到打印机"); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印错误"); } finally { pDlg.Dispose(); pDlg = null; ppDlg.Dispose(); ppDlg = null; } }
/// <summary> /// Show a PrintPreviewDialog for the specified PrintDocument. /// </summary> /// <param name="pdoc">Specifies the PrintDocument to be previewed.</param> /// <param name="showPrintDialog">Specifies whether to show the PrintSettings dialog.</param> static public void ChartPreviewDialogEx(PrintDocument pdoc, bool showPrintDialog) { PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = pdoc; ToolStripButton b = null; if (showPrintDialog) { // Replace the existing Print button with one that issues a print dialog // prior to printing. This allows a printer other than default. ToolStripButton bb = (ToolStripButton)((ToolStrip)(ppd.Controls[1])).Items[0]; b = new ToolStripButton(); b.Image = bb.Image; b.DisplayStyle = ToolStripItemDisplayStyle.Image; bb.Dispose(); bb = null; ((ToolStrip)(ppd.Controls[1])).Items.RemoveAt(0); ((ToolStrip)(ppd.Controls[1])).Items.Insert(0, b); b.Click += (o, e) => { using (PrintDialog pdlg = new PrintDialog()) { pdlg.Document = ppd.Document; if (pdlg.ShowDialog(ppd) == DialogResult.OK) { pdlg.Document.PrinterSettings = pdlg.PrinterSettings; pdlg.Document.Print(); } } }; } Size screenSize = Screen.FromControl(ppd).WorkingArea.Size; ppd.ClientSize = new Size(screenSize.Width * 3 / 4, screenSize.Height * 3 / 4); ppd.ShowDialog(); ppd.Dispose(); if (b != null) { b.Dispose(); } }
protected virtual void ShowPrintPreviewDialog(System.Drawing.Printing.PrintDocument printDocument_1) { this.ThrowPrintDocumentNullException(printDocument_1); PrintPreviewDialog dialog = new PrintPreviewDialog { Text = printDocument_1.DocumentName, WindowState = FormWindowState.Maximized }; if (this.importExcelDelegate_0 != null) { ToolBar bar = null; if (dialog.Controls[1] is ToolBar) { bar = (ToolBar)dialog.Controls[1]; ToolBarButton button = new ToolBarButton { ToolTipText = "Import Excel", ImageIndex = 2 }; bar.ButtonClick += new ToolBarButtonClickEventHandler(this.method_0); bar.Buttons.Add(button); } } try { dialog.Document = printDocument_1; if (dialog.ShowDialog() != DialogResult.OK) { } } catch (InvalidPrinterException exception) { this.ShowInvalidPrinterException(exception); } catch (Exception exception2) { this.ShowPrinterException(exception2); } finally { dialog.Dispose(); dialog = null; } }
public void CloseDrawArea() { //this.SuspendLayout(); //// //// DrawArea //// //this.Load -= new System.EventHandler(this.DrawArea_Load); //this.Paint -= new System.Windows.Forms.PaintEventHandler(this.DrawArea_Paint); //this.KeyPress -= new System.Windows.Forms.KeyPressEventHandler(this.DrawArea_KeyPress); //this.MouseDoubleClick -= new System.Windows.Forms.MouseEventHandler(this.DrawArea_MouseDoubleClick); //this.MouseDown -= new System.Windows.Forms.MouseEventHandler(this.DrawArea_MouseDown); //this.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.DrawArea_MouseMove); //this.MouseUp -= new System.Windows.Forms.MouseEventHandler(this.DrawArea_MouseUp); //this.ResumeLayout(false); //_currentPen.Dispose(); //_currentBrush.Dispose(); foreach (Control control in this.Controls) { control.Dispose(); } PageSetupDialog1.Dispose(); printdoc1.Dispose(); previewdlg.Dispose(); PrintDialog1.Dispose(); if (tempobject != null) { tempobject.AreaPath.Dispose(); tempobject.AreaPen.Dispose(); tempobject.AreaRegion.Dispose(); } //((ToolObject)tools[(int)DrawToolType.Pointer]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.Rectangle]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.Ellipse]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.Line]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.PolyLine]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.Text]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.Image]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.Variable]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.Function]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.FunctionBlock]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.Wire]).m_Cursor.Dispose(); //((ToolObject)tools[(int)DrawToolType.Constant]).m_Cursor.Dispose(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void printPreview_PrintClick(object sender, EventArgs e) { try { printDialog1.Document = _printDocument; if (printDialog1.ShowDialog() == DialogResult.OK) { _printDocument.Print(); printPreviewDialog1.Close(); printPreviewDialog1.Dispose(); } } catch (Exception ex) { Log.WriteLine(ex); MessageBox.Show(ex.Message, ToString()); } }
public void Preview() { PrintPreviewDialog ppDlg = new PrintPreviewDialog(); try { ppDlg.Text = "打印预览"; ppDlg.WindowState = FormWindowState.Maximized; ppDlg.PrintPreviewControl.Zoom = 1; //指定打印文档 ppDlg.Document = document; //显示对话框 // ppDlg.FindForm().Visible = false; DialogResult result = ppDlg.ShowDialog(); // ppDlg.FindForm().Visible = true; if (result == DialogResult.OK) { //... } } catch (System.Drawing.Printing.InvalidPrinterException e) { MessageBox.Show("请先在控制面板添加打印机!", "未找到打印机"); //ShowInvalidPrinterException(e); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印错误"); } finally { ppDlg.Dispose(); ppDlg = null; } }
public void PrintPreview(string Printer, string PaperType, string Tray, uint FromPage, uint ToPage, int Language) { PrinterSettings p; bool bGood = false; p = new PrinterSettings(); if (PrinterSettings.InstalledPrinters.Count > 0) { foreach (string s in PrinterSettings.InstalledPrinters) { if (s.Equals(Printer, StringComparison.OrdinalIgnoreCase)) { p.PrinterName = s; bGood = true; } } if (!bGood) { p.PrinterName = PrinterSettings.InstalledPrinters[0]; bGood = true; } } if (bGood == false) { MessageBox.Show("No installed printers were found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } PreparePrint(Printer, PaperType); this.FromPage = FromPage; this.ToPage = ToPage; this.NextPage = FromPage; this.Language = Language; PrintDocument printDocument = new PrintDocument(); printDocument.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); printDocument.PrinterSettings = p; PaperSize gevondenSize = null; foreach (PaperSize ps in printDocument.PrinterSettings.PaperSizes) { if (ps.PaperName.Equals(PaperType, StringComparison.OrdinalIgnoreCase)) { gevondenSize = ps; break; } } if (gevondenSize == null) { System.Drawing.Printing.PrinterSettings.PaperSizeCollection col; col = printDocument.PrinterSettings.PaperSizes; Tools.Size theSize = PaperDef.GetLabelSize(); PaperSize sz = new PaperSize(PaperType, (int)(PaperDef.GetPhysicalLabelSize().Width.InInch() * 100), (int)(PaperDef.GetPhysicalLabelSize().Height.InInch() * 100)); //PaperSize sz = new PaperSize(PaperType, (int)(PaperDef.GetPhysicalLabelSize().Width.InInch() * 96), (int)(PaperDef.GetPhysicalLabelSize().Height.InInch() * 96)); //TODO: DPI values printDocument.PrinterSettings.DefaultPageSettings.PaperSize = sz; } else { printDocument.PrinterSettings.DefaultPageSettings.PaperSize = gevondenSize; } if ((FromPage > 0) || (ToPage != uint.MaxValue)) { printDocument.PrinterSettings.PrintRange = PrintRange.SomePages; printDocument.PrinterSettings.FromPage = (int)FromPage; printDocument.PrinterSettings.ToPage = (int)ToPage; } else { printDocument.PrinterSettings.PrintRange = PrintRange.AllPages; } printDocument.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); printDocument.DocumentName = "Preview document"; printDocument.DefaultPageSettings.PaperSource.SourceName = Tray; PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog(); printPreviewDialog.Document = printDocument; printPreviewDialog.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; printPreviewDialog.UseAntiAlias = true; //remove later if proves to be to slow. ((ToolStrip)printPreviewDialog.Controls[1]).Items[0].Enabled = false; printPreviewDialog.ShowDialog(); StaticVarslabel.Values.Clear(); //Clear static variables after printjob printPreviewDialog.Dispose(); }
private void printDocument_BeginPrint(object sender, PrintEventArgs e) { IsComplete = false; // set start page and end page if (printDocument.PrinterSettings.PrintRange == PrintRange.CurrentPage) { int selectedPage = 0; for (int i = 0; i < pages.Count; i++) { if (pages[i].IsSelected) { selectedPage = i; } } pagesIndex = selectedPage; lastPrintPage = selectedPage; } else if (printDocument.PrinterSettings.PrintRange == PrintRange.SomePages) { int from = printDocument.PrinterSettings.FromPage; int to = printDocument.PrinterSettings.ToPage; if (from <= 0) { from = 1; } if (from > pages.Count) { from = pages.Count; } if (to < from) { to = from; } if (to > pages.Count) { to = pages.Count; } pagesIndex = from - 1; lastPrintPage = to - 1; } else { pagesIndex = 0; lastPrintPage = pages.Count - 1; } if (isShowPrintDialog && !isPDFPrint) { PrintDialog MyPrintDg = new PrintDialog(); MyPrintDg.UseEXDialog = true; MyPrintDg.Document = printDocument; printDocument.DefaultPageSettings.Landscape = report.Landscape; try { printDocument.DefaultPageSettings.PaperSize.RawKind = (int)PaperKind.A4; } catch { } // will throw exception when no default printer is set if (MyPrintDg.ShowDialog() == DialogResult.OK) { if (MyPrintPreviewDg != null) { MyPrintPreviewDg.Dispose(); } } else { e.Cancel = true; } MyPrintDg.Dispose(); } }