C # print the barcode through the barcode printer (banma printer)

Source: Internet
Author: User
Tags print object

I have been logging onto the blog for a long time. I have just been in the development field for a year. I don't know what to write on my blog. Now I want to share some of my work experience with bar code printers.CodeI hope to give some help to scholars. I have a limited level and cannot write much. The specific code is as follows:

// Enable the serial port of the printer.

Internal class barcodeprinter
{

// Port
Private string filename;

Public barcodeprinter (string port)
{
This. filename = port;
}

[Dllimport ("printedll. dll")]
Private Static extern int closeprinter ();

// Obtain the print command
Public String getlabelcommand (string filename)
{
Streamreader reader = new streamreader (filename );
String STR = "";
String str2 = NULL;
While (str2 = reader. Readline ())! = NULL)
{
STR = STR + str2;
}
Reader. Close ();
Return STR;
}

[Dllimport ("printedll. dll")]
Private Static extern int openprinter (string filename );

// Print the barcode
Public void printlabel (string text)
{
If (openprinter (this. filename) <0)
{
Throw new exception ("tag printing: Open" + this. filename + "failed. ");
}
Write (text );
Closeprinter ();
}

[Dllimport ("printedll. dll")]
Private Static extern int write (string text );
}

 

 

// Call

// Instantiate the Print Object

Barcodeprinter v_barcode_printer = new pack_barcode.model.barcodeprinter (Serial Port );

// Zpl II language (For details, refer to zpl II description)

String strprint = "^ XA
^ Lh0, 0
^ Fo60, 303 ^ gb1100, 0, 10 ^ FS
^ Fo550, 303 ^ gb0, 647,10 ^ FS
^ Fo120, 670 ^ A0, 25, 40 ^ fdpn: $ P ^ FS
^ Xz ";

// Print method.

Private void printtext (string Str)

{

V_barcode_printer .. printlabel (strprint. Replace ("$ P", STR );

}

 

 

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.