Bar code printing

Source: Internet
Author: User

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 ;}}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.