<pre> Bitmap bitmap; private void btnPrint_Click(object sender, EventArgs e) { panel1.AutoScroll = false; btnPrint.Visible = false; ddlPrinters.Visible = false; //Add a Panel control. Panel panel = new Panel(); this.Controls.Add(panel); // this.Controls.Add(panel1); //Create a Bitmap of size same as that of the Form. //Graphics grp = panel1.CreateGraphics(); Graphics grp = panel.CreateGraphics(); Size formSize = this.panel1.ClientSize; bitmap = new Bitmap(formSize.Width, formSize.Height, grp); grp = Graphics.FromImage(bitmap); //Copy screen area that that the Panel covers. Point panelLocation = PointToScreen(panel.Location); //Point panelLocation = PointToScreen(panel1.Location); grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize); ////Show the Print Preview Dialog. //printPreviewDialog1.Document = printDocument1; //printPreviewDialog1.PrintPreviewControl.Zoom = 1; //printPreviewDialog1.ShowDialog(); // printDialog1.ShowDialog(); PrintCard(); } private void PrintCard() { StandardPrintController spController = new StandardPrintController(); this.printDocument1 = new PrintDocument(); this.printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage); //this.m_printDocument.PrinterSettings.PrinterName = this.strPrinterName; this.printDocument1.PrinterSettings.PrinterName = this.ddlPrinters.Text; this.printDocument1.DefaultPageSettings.Landscape = true; // this.printDocument1 = 1; // this.printDocument1 = 2; this.printDocument1.DefaultPageSettings.Margins = new Margins(0, 20, 0, 0); this.printDocument1.DefaultPageSettings.Landscape = true; this.printDocument1.PrinterSettings.Duplex = Duplex.Horizontal; this.printDocument1.PrinterSettings.DefaultPageSettings.Color = true; // this.printDocument1.QueryPageSettings += new QueryPageSettingsEventHandler(this.printDocument1_QueryPageSettings); this.printDocument1.PrinterSettings.Copies = 1; this.printDocument1.PrintController = spController; this.printDocument1.OriginAtMargins = true; // this.printDocument1 = 0; this.printDocument1.DocumentName = "QR Printing"; this.printDocument1.Print(); } private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { //Print the contents. // e.Graphics.DrawImage(bitmap, 140, 20); e.Graphics.DrawImage(bitmap, 20, 60); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)