资源简介

ZPL指令 斑马打印机 网络打印 驱动打印 C# WinForm&WinCE;

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.Win32.SafeHandles;
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics;
using System.Drawing;

namespace MXM
{
    class Common
    {
        [DllImport(“kernel32.dll“ SetLastError = true)]
        static extern SafeFileHandle CreateFile(string lpFileName FileAccess dwDesiredAccess
        uint dwShareMode IntPtr lpSecurityAttributes FileMode dwCreationDisposition
        uint dwFlagsAndAttributes IntPtr hTemplateFile);

        /// 
        /// 打印标签
        /// 

        /// 箱子二维码
        /// 
        public bool printBoxQRCode(string boxQRCode)
        {
            try
            {
// ZPL指令,可参考ZPL语言中文手册,自己修改(最简单的学习方法就是本机安装bartender
// 可手动生成ZPL指令)
                string ZPLString = “^XA“
+ “^PW1240“
+ “~SD17.0“
+ “^FO1452^GB78303^FS“
+ “^FO347420^GB44703^FS“
+ “^FO14809^GB78303^FS“
+ “^FO141064^GB78303^FS“
+ “^FO1452^GB010133^FS“
+ “^FO12352^GB010133^FS“
+ “^FO23553^GB010133^FS“
+ “^FO34652^GB010133^FS“
+ “^FO457420^GB06443^FS“
+ “^FO568420^GB06443^FS“
+ “^FO680420^GB06443^FS“
+ “^FO79253^GB010133^FS“
+ “^FO8010^BQB310^FDLA“ + boxQRCode + “^FS“
+ “^FO11064^A0B6028^FD“ + boxQRCode + “^FS“
+ “^PQ101Y“
+ “^XZ“;
                if (communicate == “2“)
                {
                    // 驱动直连打印
string PrinterName = “PrinterName“;//打印机名称,需要在本机上安装打印机驱动
                    RawPrinterHelper.SendStringToPrinter(PrinterName ZPLString);
                }
                else
                {
                    // IP地址打印(手持端支持网络不支持直连)
                    System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
string IPAddress = “IPAddress“;// 打印机的网络地址
                    client.Connect(IPAddress 9100);
                    StreamWriter writer = new StreamWriter(client.GetStream());
                    writer.Write(ZPLString);
                    writer.Flush();
                    writer.Close();
                    client.Close();
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
    }


    public class RawPrinterHelper
    {
        // Structure and API declarions:
        [StructLayout(LayoutKind.Sequential CharSet = CharSet.Ansi)]
        public class DOCINFOA
        {
            [MarshalAs(UnmanagedType.LPStr)]
            public string pDocName;
            [MarshalAs(UnmanagedType.LPStr)]
            public string pOutputFile;
            [MarshalAs(UnmanagedType.LPStr)]
            public string pDa

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       9100  2017-12-19 10:17  Common.cs

     文件    7446826  2014-04-07 22:05  ZPL语言中文手册.pdf

----------- ---------  ---------- -----  ----

              7455926                    2


评论

共有 条评论