Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Runtime.InteropServices;
Namespace Barcodelibrary
{
public class Zebragesigner
{
[StructLayout (LayoutKind.Sequential)]
private struct OVERLAPPED
{
int Internal;
int Internalhigh;
int Offset;
int Offsethigh;
int hevent;
}
[DllImport ("kernel32.dll")]
private static extern int CreateFile (string lpfilename, uint dwdesiredaccess, int dwsharemode, int lpsecurityattributes, I NT dwCreationDisposition, int dwflagsandattributes, int htemplatefile);
[DllImport ("kernel32.dll")]
private static extern bool WriteFile (int hfile, byte[] lpbuffer, int nnumberofbytestowriter, out int lpnumberofbyteswriten , out OVERLAPPED lpoverlapped);
[DllImport ("kernel32.dll")]
private static extern bool CloseHandle (int hobject);
[DllImport ("Fnthex32.dll")]
public static extern int Getfonthex (string barcodetext,string fontname,int orient,int height,int width,int isbold,int IsI Talic,stringbuilder returnbarcodecmd);
private int ihandle;
Open LPT port
public bool Open ()
{
Ihandle = CreateFile ("lpt1", 0x40000000, 0, 0, 3, 0, 0);
if (ihandle! =-1)
{
return true;
}
Else
{
return false;
}
}
Print functions, parameters for printer commands or other text!
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 ("Port is not open!") ");
}
}
Close the print port
public bool Close ()
{
return CloseHandle (Ihandle);
}
}
}
*************************************
vate void Button1_Click (object sender, EventArgs e)
{
Zebragesigner ZB = new Zebragesigner ();
String mycommanglines = System.IO.File.ReadAllText ("Print.txt");//print.txt wrote the Order of the barcode machine.
Zb. Open ();
Zb. Write (Mycommanglines);
Zb. Close ();
}
C # Send printer commands directly to printer ++++