Winform print invoice and winform print
Background code
1 panPrintContent. visible = true; 2 var strlPrinterMode = ""; 3 4 this. pageSetupDialog1.PageSettings. margins. left = 1; 5 this. pageSetupDialog1.PageSettings. margins. top = 1; 6 this. pageSetupDialog1.PageSettings. margins. right = 21; 7 this. pageSetupDialog1.PageSettings. margins. bottom = 21; 8 panPrintContent. visible = true; 9 10 // print settings 11 try12 {13 string sqls = "select PrinterMode from User_Org where U SerID = '"+ DBCommonServer. strUserName + "'and OID ='" + DBCommonServer. strOrgId + "'"; 14 DataTable dt1 = helps. getDataTable (sqls); 15 if (dt = null) 16 {17 return; 18} 19 if (dt1.Rows. count> 0) 20 {21 strlPrinterMode = dt1.Rows [0] [0]. toString (); 22} 23 if (strlPrinterMode = "0") 24 {25 this. printPreviewDialog1.ShowDialog (); 26} 27 else28 {29 for (int I = 0; I <Convert. toInt32 (strlPrinterMode); I ++) 3 0 {31 32 this. printDocument1.Print (); 33} 34} 35} 36 catch (Exception) 37 {38 MessageBox. Show ("Hello! Your computer may be unable to start or install a printer. "39 + Environment. NewLine + Environment. NewLine +" please start the Print Service or install the printer first! "); 40}View Code 1 // <summary> 2 // print content 3 /// </summary> 4 // <param name = "sender"> </param> 5 /// <param name = "e"> </param> 6 private void printDocument1_PrintPage_1 (object sender, system. drawing. printing. printPageEventArgs e) 7 {8 // print the content as partial this. groupBox1 9 Bitmap _ NewBitmap = new Bitmap (this. panPrintContent. width, this. panPrintContent. height); 10 this. panPrintContent. drawToBitmap (_ NewBitmap, new Rectangle (0, 0, _ NewBitmap. width, _ NewBitmap. height); 11 e. graphics. drawImage (_ NewBitmap, 0, 0, _ NewBitmap. width, _ NewBitmap. height); 12}View Code
Dynamically Retrieve controls
1 int iheight = iLabHeight * I; 2 Label LlabPrintPayType = new Label (); 3 LlabPrintPayType. name = "LlabPrintPayType" + I; 4 // LlabPrintPayType. location = new Point (ilabPrintPayType_X, ilabPrintPayType_Y + iheight); 5 LlabPrintPayType. location = new Point (25, I * 20 + 20); 6 LlabPrintPayType. text = dtlistPay. rows [I] ["Payment Method Name"]. toString () + (dtlistPay. rows [I] ["card number"]. toString () = ""? "": "(" + DtlistPay. rows [I] ["card number"]. toString () + ")"); 7 LlabPrintPayType. height = 20; 8 panFkfs. controls. add (LlabPrintPayType); 9 Label LlabPrintCost = new Label (); 10 LlabPrintCost. name = "LlabPrintCost" + I; 11 LlabPrintCost. location = new Point (170, I * 20 + 20); 12 string strPrintCost = decimal. round (Convert. toDecimal (dtlistPay. rows [I] ["amount"]. toString (), 2, MidpointRounding. awayFromZero ). toString ();View Code
Front-end code