The latest project requires barcode printing ~~ We used a simple method to directly call a bar code object to generate an image print --
1 using System; 2 using System. collections. generic; 3 using System. text; 4 /// <summary> 5 // Print Code 6 /// </summary> 7 public sealed class PrintBarcode 8 {9 BarcodeLib. barcode _ Barcode; 10 public PrintBarcode () 11 {12 13 _ Barcode = new BarcodeLib. barcode (); 14 _ Barcode. includeLabel = true; 15} 16 17 public System. drawing. use BarcodeLib for Image Fill (string BarcodeText) 18 {19 // --- length of 12 or 13. TYPE. EAN13: This encoding accounts for 20 20 if (BarcodeText. length> = 12 & BarcodeText. length <= 13) 21 {22 return _ Barcode. encode (BarcodeLib. TYPE. EAN13, BarcodeText, 100, 50); 23} 24 25 26 // ------------------- here we can adapt to the return _ Barcode position less than 13. encode (BarcodeLib. TYPE. CODE128, BarcodeText, 100,50); 28} 29 30 31 32}
Output again. Use pb. Fill to adapt to the bar code text ~~
BLL. printBarcode pb = new PrintBarcode (); /// <summary> /// print the event /// </summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> private void pd_PrintPage (object sender, printPageEventArgs e) {// --- print the message cyclically and start printing for (int Index = PrintIndex; Index <MessingList. printMessing. count; Index ++) {IPrintMessing TempMessing = MessingList. printMessing [Index]; // --- font size int FontSize = MessingList. styleList. style [TempMessing. id]. fontSize; // ---- special code processing if (MessingList. styleList. style [TempMessing. id]. type = PrintStyleType. barcode) {e. graphics. drawImage (pb. fill (TempMessing. printValue), new System. drawing. point (TempMessing. print_X, TempMessing. print_Y);} else {e. graphics. drawString (TempMessing. printValue, new System. drawing. font (new System. drawing. fontFamily (""), FontSize), System. drawing. brushes. black, TempMessing. print_X, TempMessing. print_Y);} // -- print and determine whether the page ends if (TempMessing. isPageEnd) {if (Index> = MessingList. printMessing. count-1) {// --- New PrintIndex = 0; return;} else {// --- re-execute the pd_PrintPage event e. hasMorePages = true; // --- negative value print pointer to print, skip the current Index PrintIndex = Index + 1; // --- judge the end of a page // ---- jump out of the loop return ;}}}