Let more people know how to operate a Zebra barcode printer in C #

Source: Internet
Author: User
Here is the Barcode printing program I developed for barcode printing
Using System;
Using System.IO;
Using System.Collections.Generic;
Using System.Text;

Namespace Barcode
{
/* Barcode Printing Command Description
^XA//Barcode Printing Instructions Start
^MD30//sets the color depth of the ribbon, ranging from 30 to 30
^lh60,10//Set margin of barcode paper
^fo20,10//Set barcode position in upper-left corner
^acn,18,10//Set Font
^by1.4,3,50//Set bar code style. 1.4 is the bar code scaling level, 3 is the bar code in the proportion of thick and thin, 50 is the bar code height
^bc,,y,n//Print code128 instructions
^FD12345678^FS//Set the content to be printed, ^FD is the bar code content to be printed ^fs indicates a newline
^XZ//Barcode Print instruction End
*///The above instruction will print 12345678 CODE128 barcode
public class Barcodeprint
{
[System.Runtime.InteropServices.StructLayout (System.Runtime.InteropServices.LayoutKind.Sequential)]
Private struct OVERLAPPED
{
int Internal;
int Internalhigh;
int Offset;
int Offsethigh;
int hevent;
}
[System.Runtime.InteropServices.DllImport ("kernel32.dll")]
private static extern int CreateFile (string lpfilename, uint dwdesiredaccess, int dwsharemode, int lpsecurityattributes, I NT dwCreationDisposition, int dwflagsandattributes, int htemplatefile);
[System.Runtime.InteropServices.DllImport ("kernel32.dll")]
private static extern bool WriteFile (int hfile, byte[] lpbuffer, int nnumberofbytestowrite, out int lpnumberofbyteswritten , out overlapped lpoverlapped);
[System.Runtime.InteropServices.DllImport ("kernel32.dll")]
private static extern bool CloseHandle (int hobject);
private int ihandle;
public bool Open ()
{
Ihandle = CreateFile ("LPT1:", (UINT) fileaccess.readwrite, 0, 0, (int) filemode.open, 0, 0);
if (Ihandle!=-1)
{
return true;
}
Else
{
return false;
}
}
public bool Write (string Mystring)
{
if (Ihandle!=-1)
{
int i;
Overlapped x;
byte[] MyByte = System.Text.Encoding.Default.GetBytes (Mystring);
Return WriteFile (Ihandle, MyByte, MyByte. Length, out I, out x);
}
Else
{
throw new Exception ("LPT1 Port not open!");
}
}
public bool Close ()
{
return CloseHandle (Ihandle);
}
}
}


How to print Chinese see below: Using the Getfonthex function
C # prototype used by the function:
[DllImport ("Fnthex32.dll")]
public static extern int Getfonthex (
String Barcodetext,
String FontName,
String FileName,
int Orient,
                               int height,

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.