/// <summary> ///the printed button/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidBtnprint_click (Objectsender, EventArgs e) { //printDocument1 for print controls//set the paper for printing when set to custom, you can customize the size of the paper, you can also choose A4,a5 and other common paper type This. printDocument1.DefaultPageSettings.PaperSize =NewPaperSize ("Custom", -, -); This. printdocument1.printpage + =NewPrintpageeventhandler ( This. Myprintdocument_printpage); //give the print preview control a well-written format for previewingPrintpreviewdialog1.document =PrintDocument1; //Show Print PreviewDialogResult result =Printpreviewdialog1.showdialog (); } /// <summary> ///format of printing/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidMyprintdocument_printpage (Objectsender, System.Drawing.Printing.PrintPageEventArgs e) { /*If you need to change yourself in the new font ("bold"), the "Blackbody" in the FontFamily is changed to the font you want, the number behind the blackbody represents the size of the font System.Drawing.Brushes.Blue , 170, 10 System.Drawing.Brushes.Blue is color, the back is the position of the output*/e.graphics.drawstring ("Xinxiang March software company Warehousing Order",NewFont (NewFontFamily ("blackbody"), One), System.Drawing.Brushes.Black, the,Ten); E.graphics.drawstring ("Supplier: Henan Institute of Science and Technology",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Blue,Ten, A); //the name of the messageE.graphics.drawline (Pens.black,8, -,480, -); E.graphics.drawstring ("Inbound Order Number",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black,9, *); E.graphics.drawstring ("Product Name",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black, the, *); E.graphics.drawstring ("Quantity",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black,260, *); E.graphics.drawstring ("Unit Price",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black, the, *); E.graphics.drawstring ("Total Amount",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black, -, *); E.graphics.drawline (Pens.black,8, -,480, -); //Product InformationE.graphics.drawstring ("r2011-01-2016:06:35",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black,9, -); E.graphics.drawstring ("Lenovo A460",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black, the, -); E.graphics.drawstring (" -",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black,260, -); E.graphics.drawstring ("200.00",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black, the, -); E.graphics.drawstring ("20000.00",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black, -, -); E.graphics.drawline (Pens.black,8, $,480, $); E.graphics.drawstring ("Address: Xinxiang College of Information Engineering, Henan University of Science and Technology",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black,9, About); E.graphics.drawstring ("Manager : Ren bogey",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black, -, About); E.graphics.drawstring ("Service Hotline: 15083128577",NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black, the, About); E.graphics.drawstring ("Storage Time:"+ DateTime.Now.ToString (),NewFont (NewFontFamily ("blackbody"),8), System.Drawing.Brushes.Black,9, the); }
C # enables printing capabilities to set paper size, font and color